Android applications can be multi-process. Android OS allows multiple applications to run concurrently, provide memory and processing power is available.
Application can have background processes, and application can be interrupted and paused when event such as phone call occurs.
There can be only one active application visible to the user at a time. (Specifically a single application Activity is in the foreground at any given time.)
Android OS keeps track of all activity objects running by placing them on Activity stacks. When a new Activity starts, the Activity on thetop of the stack (the current foreground Activity) pauses, and the new Activity pushes onto the top of the stack.
When that Activity finishes that Activity is removed from the activity stack, and the previous Activity in the stack resumes.
Has a single parameter, a Bundle, which is null if this is a newly started Activity.
Activity was killed for memory reasons and is now restarted, the Bundle contains the previous state information for this Activity so that it can reinitiate.
Appropriate to perform any setup, such as layout and data binding in the onCreate() method.
Calls to the setContentView() method.
Most appropriate place to retrieve any instances to resources.
Resources are the most process-intensive, so we only keep these around while the Activity is in the foreground.
The onResume() method is the appropriate place to start audio, video, and animations.
Need to save any uncommitted data here, in case your application does not resume.
The new foreground Activity is not started until the onPause() method returns.
Any resources and data retrieved in the onResume() method should be released in the onPause() method.
If they aren’t, there is a chance that these resources can’t be cleanly released if the process is terminated.
onDestroy()
When an Activity is being destroyed, the onDestroy() method is called.
The onDestroy() method is called for one of two reasons:
–The Activity has completed its lifecycle voluntarily
–Activity is being killed by the Android operating system because it needs the resources.
The isFinishing() method returns false if the Activity has been killed by the Android operating system.
activity that has been
– Paused.
– Stopped.
– Destroyed.
Any activity which is not in foreground is subject to shutdown.
If the Activity is killed after onPause(), the onStop() and onDestroy() methods might not be called.
Killing an Activity does not remove it from the activity stack.
Instead, the activity state is saved into a Bundle object.
Application can have background processes, and application can be interrupted and paused when event such as phone call occurs.
There can be only one active application visible to the user at a time. (Specifically a single application Activity is in the foreground at any given time.)
Android OS keeps track of all activity objects running by placing them on Activity stacks. When a new Activity starts, the Activity on thetop of the stack (the current foreground Activity) pauses, and the new Activity pushes onto the top of the stack.
When that Activity finishes that Activity is removed from the activity stack, and the previous Activity in the stack resumes.
onCreate()
An Activity first starts, the onCreate() method is called.Has a single parameter, a Bundle, which is null if this is a newly started Activity.
Activity was killed for memory reasons and is now restarted, the Bundle contains the previous state information for this Activity so that it can reinitiate.
Appropriate to perform any setup, such as layout and data binding in the onCreate() method.
Calls to the setContentView() method.
onResume()
Method is called when à Activity reaches the top of the activity stack and becomes the foreground process.Most appropriate place to retrieve any instances to resources.
Resources are the most process-intensive, so we only keep these around while the Activity is in the foreground.
The onResume() method is the appropriate place to start audio, video, and animations.
onPause()
When another Activity moves to the top of the activity stack, the current activity is informed that it is being pushed down the activity stack by way of the onPause() method.
Activity should stop any audio, video, and animations it started in the onResume() method.
Deactivate resources such as database Cursor objects if opted to manage them manually, as opposed to having them managed automatically.
To clean up and release any resources it does not need while in the background.Need to save any uncommitted data here, in case your application does not resume.
The new foreground Activity is not started until the onPause() method returns.
Any resources and data retrieved in the onResume() method should be released in the onPause() method.
If they aren’t, there is a chance that these resources can’t be cleanly released if the process is terminated.
onSaveInstanceState()
The more resources released by an Activity in the onPause() method, the less likely the Activity is to be killed while in the background.
Activity can save state information to a Bundle object using the onSaveInstanceState() callback method.
This call is not guaranteed under all circumstances, so use the onPause() method for essential data commits.
When this Activity is returned to later, this Bundle is passed into the onCreate() method, allowing the Activity to return to the exact state it was in when the Activity paused.
onRestoreInstanceState() à read Bundle information after the onStart() callback method.onDestroy()
When an Activity is being destroyed, the onDestroy() method is called.
The onDestroy() method is called for one of two reasons:
–The Activity has completed its lifecycle voluntarily
–Activity is being killed by the Android operating system because it needs the resources.
The isFinishing() method returns false if the Activity has been killed by the Android operating system.
Avoiding Activity Objects Being Killed
Under low-memory conditions, the Android operating system can kill the process for anyactivity that has been
– Paused.
– Stopped.
– Destroyed.
Any activity which is not in foreground is subject to shutdown.
If the Activity is killed after onPause(), the onStop() and onDestroy() methods might not be called.
Killing an Activity does not remove it from the activity stack.
Instead, the activity state is saved into a Bundle object.
When the user returns to the Activity later, the onCreate() method is called again, this time with a valid Bundle object as the parameter.




Posted in: 
0 comments:
Post a Comment