• Like
  • Save
Android crashcourse
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Android crashcourse

  • 734 views
Published

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
734
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Android Crashcourse@AlexeyBuzdin 15.06.2013
  • 2. AndroidJava SE + Android.jarDalvik runtimeComponent based MVC
  • 3. Project Structure
  • 4. Project StructureSource code in JavaImages, gradients, etcUI written in XMLReference Data (Strings, colors, arrays)App config file
  • 5. Activity
  • 6. Activitypublic class TestActivity extends Activity {@Overrideprotected void onCreate(Bundle savedState) {super.onCreate(savedState);setContentView(R.layout.main);}}
  • 7. Activity states
  • 8. ContextInterface to global information about anapplication environment.Up-calls for application-level operations suchas launching activities, broadcasting andreceiving intents, etc.
  • 9. Context examplesTextView text = new TextView(context);new ArrayAdapter(context, R.layout.item, myList)context.getExternalCacheDir()context.getResources()context.startActivity(navigationIntent)
  • 10. R.javapublic class TestActivity extends Activity {@Overrideprotected void onCreate(Bundle savedState) {super.onCreate(savedState);setContentView(R.layout.main);}}
  • 11. R.java (resource)Auto generated interface between src and androidresources. Used only for compilation time.
  • 12. R.java
  • 13. Project Structure
  • 14. Views
  • 15. ViewsViews - TextView, EditText, Button ...ViewGroup - LinearLayout, RelativeLayout ...AdapterView - Spinner, Gallery, ListView ...
  • 16. res/layout/<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"></LinearLayout>
  • 17. res/layout/<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextView android:id="@+id/textView"android:layout_height="wrap_content"android:layout_width="wrap_content"android:text="@string/app_name"/></LinearLayout>
  • 18. res/layout/
  • 19. Views. Java part@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);TextView text = (TextView) findViewById(R.id.textView);}
  • 20. Views. Java part@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);TextView text = (TextView) findViewById(R.id.textView);text.findViewById(0); // same method invocation}
  • 21. Under the hood. LayoutInflaterLayoutInflater inflater = context.getLayoutInflater();View view = inflater.inflate(R.layout.main, null);
  • 22. Under the hood. LayoutInflater@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);LayoutInflater inflater = context.getLayoutInflater();View view = inflater.inflate(R.layout.main, null);setContentView(view);TextView text = (TextView) view.findViewById(R.id.textView);}
  • 23. Event HandlingButton button = new Button(context);button.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v){Toast.makeText(MyActivity.this, "HelloWorld", Toast.LENGTH_SHORT).show();}});
  • 24. Event HandlingFor ViewsOnLongClickListenerOnSelectListenerOnHoverListener.....For AdapterViewOnItemClickListenerOnItemLongClickListener
  • 25. TextView
  • 26. ListView?
  • 27. Adapter
  • 28. AdapterViewGallery gallery = (Gallery) findViewById(R.id.gallery);ArrayList<String> list = new ArrayList<String>();gallery.setAdapter(new ArrayAdapter<String>(this, 0, list){@Overridepublic View getView(int position, View convertView,ViewGroup parent) {// 1. Check if view already exists// 2. If not - Inflate view// 3. Populate viewreturn view;}});
  • 29. IntentAbstract description of an operation to be performed.External IntentsOpen URLCall a PersonShare an ImageInternal IntentsStart Activity
  • 30. ExampleIntent intent = new Intent(context, SecondActivity.class);startActivity(intent);Intent intent = new Intent(context, SecondActivity.class);intent.putExtra("url", url);intent.putExtra("bean", serializable);startActivity(intent);
  • 31. Exampleprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.article_detail);String s = getIntent().getStringExtra("url");Bean b = (Bean)getIntent().getSerializableExtra("bean");}
  • 32. AndroidManifest<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="lv.ldn.rssreader"android:versionCode="1"android:versionName="1.0" ><uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16" /><uses-permission android:name="android.permission.INTERNET" /><application android:icon="@drawable/starred" android:label="@string/app_name"><activity android:name=".MyActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>
  • 33. AndroidManifest<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="lv.ldn.rssreader"android:versionCode="1"android:versionName="1.0" ><uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16" /><uses-permission android:name="android.permission.INTERNET" /><application android:icon="@drawable/starred" android:label="@string/app_name"><activity android:name=".MyActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name=".SecondActivity"/></application></manifest>
  • 34. AsyncTaskpublic class MyTask extends AsyncTask<Integer, Void, String>{protected void onPreExecute() {}protected String doInBackground(Integer... integers) {return null;}protected void onPostExecute(String result) {}}
  • 35. AsyncTaskMyTask task = new MyTask();task.execute(value)