![Page 1: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/1.jpg)
![Page 2: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/2.jpg)
Android - Overview What is different about Android? Application Components Inter Application Communication Activity Life Cycles
![Page 3: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/3.jpg)
What is Android?
![Page 4: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/4.jpg)
Application Components Activities
Visual user interface Hierarchy of Views
Services Background processes (playing music, etc..)
Broadcast Receivers Low battery, time zone change, etc..
Content Providers Allows data sharing between applications
![Page 5: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/5.jpg)
Activating Components ContentProvider
Activated when targeted by a ContentResolver
Intents Start: Activities, Services, BroadcastReceivers Activities, services: names the action and the data BroadcastReceivers: names the action being announced.
![Page 6: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/6.jpg)
Example intent
Intent i = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, “/sdcard/odk/sounds”);
startActivityForResult(i, AUDIO_RECORDING);
protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent);
switch (requestCode) { case AUDIO_RECORDING:
….. }
![Page 7: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/7.jpg)
Activities vs. Tasks Activity is a screen Task is a group of Activities
Not necessarily defined in the same Application. Stack of activities. Activities can only be pushed and popped. All activities in a task move as one, i.e. all go to background and
or all to foreground at once.
![Page 8: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/8.jpg)
Activity Lifecycle
![Page 9: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/9.jpg)
Activities Lifecycle Screen rotation will completely kill and restart your
program.
onPause() onStop() onDestroy()
onCreate() …
A new instance of your application is created
![Page 10: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/10.jpg)
Activities – Saving State Primitives, parcelables, serialized objects
onSaveInstanceState(Bundle outState) onRestoreInstanceState() or manually in onCreate(Bundle
savedInstanceState)
Objects onRetainNonConfigurationInstance() getLastNonConfigurationInstance()
![Page 11: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/11.jpg)
Activities - Threads UI thread
Must be quick. Respond in less than 9 seconds.
Background Threads For long activities, downloading, etc.. Use AsyncTask
![Page 12: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/12.jpg)
Views <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent“>
<Button android:id="@+id/add_button" android:text="@string/add_file" android:layout_width="wrap_content" android:layout_height="wrap_content“ android:layout_alignParentBottom=“true“ android:padding="15px" android:textSize="8pt" android:layout_weight="1"/>
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height=“fill_parent" android:layout_above="@id/upload_button" android:layout_alignParentTop="true" /> </RelativeLayout>
![Page 13: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/13.jpg)
Views <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent“>
<Button android:id="@+id/add_button" android:text="@string/add_file" android:layout_width="wrap_content" android:layout_height="wrap_content“ android:layout_alignParentBottom=“true“ android:padding="15px" android:textSize="8pt" android:layout_weight="1"/>
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height=“fill_parent" android:layout_above="@id/upload_button" android:layout_alignParentTop="true" /> </RelativeLayout>
![Page 14: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/14.jpg)
Views
onCreate() {
setContentView(R.layout.myLayout);
// where myLayout is in {project}/res/layout/myLayout.xml
Button b = (Button) findViewById(R.id.add_button);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// do something interesting;
}
});
![Page 15: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/15.jpg)
Views
onCreate() {
setContentView(R.layout.myLayout);
// where myLayout is in {project}/res/layout/myLayout.xml
Button b = (Button) findViewById(R.id.add_button);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// do something interesting;
}
});
![Page 16: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/16.jpg)
Important things… Lots o’ java
Though, there is an NDK
Intents Applications can call other applications
Activities Can get garbage collected whenever not showing Need to manage own state Can run within another application
![Page 17: Android - Overview€¦ · Application Components Activities Visual user interface Hierarchy of Views Services Background processes (playing music, etc..) Broadcast Receivers Low](https://reader034.vdocuments.site/reader034/viewer/2022050416/5f8c37dd6566ea4ff8041c1f/html5/thumbnails/17.jpg)
Tons more…
http://developer.android.com/guide