Android life cycle
Mobile device provided
limited RAM; your activity may find itself being
killed off because other activities are going on and the system needs your
activity’s memory. Think of it as the Android equivalent of the circle of life:
Your activity dies so others may live, and so on. You cannot assume that your
activity will run until you think it is complete, or even until the user thinks
it is complete. This is one example—perhaps the most important example—of how
an activity’s life cycle will affect your own application logic. In this tutorial
various states and callbacks that make up an activity’s life cycle, and how you
can hook into them appropriately.
Life cycle structure
An activity generally used four states at any point in time:
·
Active: The activity was started by the user, is running,
and is in the foreground. This is what you’re used to thinking of in terms of your
activity’s operation.
·
Paused: The activity was started by the user, is running,
and is visible, but a notification or something is overlaying part of the
screen. During this time, the user can see your activity but may not be able to
interact with it. For example, if you have doing a phone call via dual SIM Card
the user will get the opportunity to
Both SIM Call option SIM1 And SIM2
·
Stopped: Activity was started by the user, is running, but
in a background running by other activities that have been launched. Your application
will not be able to present anything meaningful to the user directly, but may
communicate by way of notifications.
·
Dead: Either the activity was never started (e.g., just
after a phone reset) or the activity was terminated.
onStart(), onRestart(), and onStop()
An activity can come to the foreground because it is first being
launched, or because it is being brought back to the foreground after having
been hidden, e.g., by another Activity or by an incoming phone call. The onStart() method is called.
The onRestart() method is called in the case where the activity had been stopped
and is now restarting.
onStop() is called when the activity is about to be stopped.
onPause() and onResume()
The onResume() method is called just before
your activity comes to the foreground, after launched, being restarted from a
stopped state, or a pop-up dialog (e.g. Battery is Low) is cleared. This is a
great place to refresh the UI based on things that
Once onPause() is called, Android reserves the
right to kill off your activity’s process at any point.
0 comments