Android Application summary:
The life cycle of an Application is the longest. After a program is created, it is destroyed after it is started. We often save some global variables to be saved in the Application instead of the Activity.
It needs to be passed and will be destroyed as the Activity is destroyed. However, Application's strength has become its weakness, because the Application will not be destroyed in the process of the program, so it is likely to save too much data OOM, or
Memory leakage (if we save a reference to an Activity, the original Activity cannot be destroyed after it jumps to another Activity ).
We can create two hashmaps <String, Object> in the Application to transfer data (through sharing) and cache some data. However, if you need to cache a large amount of data, it is best to cache some SoftReference (soft reference) and cache the data to the local ROM or local SD card. If the cache in the application does not exist, search from the local cache. If the locally cached data does not exist
Obtained on the network. To avoid being referenced by another Activity, Application, or Runable
View TextView = new TextView (this) is held by other activities, so the Activity cannot be destroyed, resulting in Memory leakage.
If we want to hold some Activity References and do not want the Activity to be destroyed, we will save these activities to the List in the Application.
Public synchronized static void register (Activity activity) {if (activityList! = Null) {for (int I = 0; I <activityList. size (); I ++) {Activity ac = activityList. get (I); if (ac. getClass (). getName () = activity. getClass (). getName () {// Delete the old one and add a new activityList. remove (ac); if (! Ac. isFinishing () {ac. finish () ;}break ;}} activityList. add (activity) ;}} public synchronized static void unregister (Activity activity) {if (activityList! = Null & activityList. size ()! = 0) {for (int I = 0; I <activityList. size (); I ++) {Activity ac = activityList. get (I); if (ac. getClass (). getName () = activity. getClass (). getName () {activityList. remove (activity); if (! Ac. isFinishing () {ac. finish () ;}}} else {Log. I ("TAG", "No Activity in Pool ");}}