厦taskUserselectstoviewActivity2thesecondsceneUser getback toMainMenuthe main menuUserselectstoviewActivity1Separateinstancethefirst sceneUserlaunchesMain Menuthe appA single activity is instantiated multiple times6
6 A single activity is instantiated multiple times. Main Menu Activity 1 Main Menu Activity 2 Separate instance task User launches the app User selects to view the first scene User get back to the main menu User selects to view the second scene
Launch Modes of ActivityThe launchMode attribute specifies an instruction on howthe activity should be launched into a taskThere are four different launch modes you can assign tothe launchMode attributeo standard: (the default mode)o singleTop:Reusetheactivityonthetopo singleTask:The systemcreates a newtaskandinstantiates the activity at the root of the new task.o singleInstanceReferto:http://inthecheesefactory.com/blog/understand-android-activity-launchmode/en7
Launch Modes of Activity • The launchMode attribute specifies an instruction on how the activity should be launched into a task • There are four different launch modes you can assign to the launchMode attribute o standard: (the default mode) o singleTop: Reuse the activity on the top o singleTask:The system creates a new task and instantiates the activity at the root of the new task. o singleInstance 7 Refer to: http://inthecheesefactory.com/blog/understand-android-activity-launchmode/en
LaunchModesofActivity<activityandroid:name=".NewsDetailActivity"android:launchMode="singleTop"><intent-filter><actionandroid:name="android.intent.action.VIEw"></action><categoryandroid:name="android.intent.category.DEFAULT"></category><categoryandroid:name="android.intent.category.BROwSABLE"/category><data android:scheme="oauth"android:host="twitt"></data></intent-filter></activity>8
Launch Modes of Activity 8 <activity android:name=".NewsDetailActivity" android:launchMode="singleTop"> <intent-filter> <action android:name="android.intent.action.VIEW"></action> <category android:name="android.intent.category.DEFAULT"></category> <category android:name="android.intent.category.BROWSABLE"></category> <data android:scheme="oauth" android:host="twitt"></data> </intent-filter> </activity>
Pass Data using Intent9
Pass Data using Intent 9
PassingDatabetweenActivitiesIntentActivity1Activity 2// Create an activity using the constructorIntent intent = new Intent(Activity1.this,Activity2.class);//Createa bundleBundle bundleData = new Bundle();// Create put string data in the bundle (key-value pair)TheBundlebundleData.putstring("key_name","name");classprovidesabundleData.putstring("key_age","age");containerfor//Create put the bundle data in the Extra of Intentstoring dataintent.putExtras(bundleData);// Invoke the activity using the created intentstartActivity(intent);10
Passing Data between Activities 10 Activity 1 Activity 2 Intent // Create an activity using the constructor Intent intent = new Intent(Activity1.this, Activity2.class); // Create a bundle Bundle bundleData = new Bundle(); // Create put string data in the bundle (key-value pair) bundleData.putString("key_name", "name"); bundleData.putString("key_age", "age"); // Create put the bundle data in the Extra of Intent intent.putExtras(bundleData); // Invoke the activity using the created intent startActivity(intent); The Bundle class provides a container for storing data