Recently re-picked up Guo Dashin's Android books to know the new.
1. Get the task stack where the activity resides, and at a glance what activity is in a task stack:
Added in OnCreate: Log.d ("Android", "Task is" +gettaskid ());
2. Observe the current activity instance in log to compare the differences between the four different startup modes:
LOG.D ("Xxactivity", this.tostring ());
3. Save data with Onsaveinstancestate ():
@Override2 protected void onsaveinstancestate (Bundle outstate) {3 Super. Onsaveinstancestate ( outstate); 4 String tempdata = "Something you just typed"; 5 outstate.putstring ("Key", "TempData"); 6 7 }
4. Recover data: Here the data is saved and the data is fetched, and intent and bundles can be used together to pass the data.
View Code
5. Know which activity interface is currently in:
The general project has a base class similar to Baseactivity, we simply print a log in the class's OnCreate method to identify the current interface:
View Code
6. Exit the app anytime, anywhere:
A dedicated collection class is required to manage all activities, and the following Activitycollector class acts as the activity Manager:
View Code
In the Activity manager, a list is used to stage the activity, and then a addactivity () method is provided to add the activity to the list, along with a removeactivity () method for removing the activity from the list, and finally providing a finishall ( ) to destroy all activities in the list.
Call: Simply add in OnCreate: Activitycollector.addactivity (this);
Added in Ondestory (): Activitycollector.removeactivity (this);
Called where all activities need to be destroyed: Activitycollector.finishall ();
1 android.os.Process.killProcess (Android.os.Process.myPid ()); KillProcess () can only be used to kill the process of the current program, not to kill other programs.
7. The best notation for initiating activities:
View Code
The basis of comparison, a good base to build high-rise.
The little tricks of activity in Android