• Must have <activity> declaration in AndroidManifest.xml. • Lots of attributes to make configurations; name is mandatory • Any activity can be main entry. <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
interface in an Activity. • Introduced in API level 11. • Use support library for API Level < 11 • Must be embedded in an activity • Fragment's lifecycle is directly affected by the host activity's lifecycle
coupled • Do not communicate with another fragment directly. • Use callback listener for interaction with activity • Use static factory method for fragment creation
create a started service: • Service • IntentService startService(new Intent(this, MyService.class)); startService(new Intent(this, MyIntentService.class))
hosting process, the service : • Does not create its own thread • Does not run in a separate process (unless you specify otherwise) Intent service • Creates a worker thread • Stop itself
by calling bindService() in order to create a long-standing connection. • Use it when you want to interact with the service from activities and other components in your app • Use it when you expose some of your application's functionality to other applications, through IPC. Intent intent = new Intent(this, MyService.class) bindService(i, mServerConn, Context.BIND_AUTO_CREATE); startService(i);
instead declare a general action to perform • Another app will handle the request • Verify that the intent will resolve to an activity For example: Open a web page if(sendIntent.resolveActivity(getPackageManager()) != null) { startActivity(sendIntent); }
matched • Often created in the android manifest, using intent-filter tags Note: An explicit intent is always delivered to its target, regardless of any intent filters the component declares. <activity android:name="ShareActivity"> <intent-filter> <action android:name="android.intent.action.SEND"/> <category android:name="android.intent.category.DEFAULT"/> <data android:mimeType="text/plain"/> </intent-filter> </activity>
call to onReceive(Context, Intent). • Use NotificationManager to show information. • You may not bind to a service from within a BroadcastReceiver, instead use Context.startService()
broadcast receiver (which holds onReceive()) is considered to be a foreground process. • It will be kept running by the system except under cases of extreme memory pressure. • After execution, the system may kill it
broadcasts across applications. • Unregister it in Activity.onPause() if registering a receiver in your Activity. onResume() • Do not use Async operation onReceive() method, use Services if API level < 11 • You can use goAsync() method for Async operation after API Level 11