What are the life cycle methods of android activity ? elaborate
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our W3Make Forum to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
The ongoing screen visible to the user using any app is termed technically an “Activity”. It represents a single screen of the app that the user is using, in such a way there are many screens just in one app which means there are numerous activities listed. Now to manage such activities we have a life cycle called the activity life cycle, which simply explains to us the process from starting and destroying phase.
–> The activity in the foreground of the screen, visible to the user means it’s at the top of the stack and it is called running or the latest activity.
–> Now in 2nd scenario suppose multi-activity is seen or one can say, a transparent activity has focused on top, this doesn’t mean that the priority of the previous activity is gone. Now both activities are alive to be noted.
–> Suppose an activity is completely hidden because of another activity, such as retaining the information, they are on the pause state and are not yet killed, but anytime they are likely to, be as soon as the system needs memory for some other activity which has higher priority.
–> In the end it’s all about the system destroying the activity from the memory, by either completely deleting or making the ongoing activity finish completely, and the activity can then restart the whole thing again to restore to its previous state.
so to check whether the system has destroyed or made the activity finish user can check it by the isFinishing() method can be called.
There are 7 methods as we say to have their individual significance in the life cycle:
all static work is done here, eg binding the data or creating the views.
Invoked when the activity is visible or the screen of the following app is visible to the user. It is the stage when the activity is first started.
When the activity is stopped and revived from the background this method is invoked and it is then followed by the OnStart() method always.
As the word describes, resume means to start something that has been stopped for a while or kept the screen at halt, followed by onPause.
This is when the activity goes in the background or is stopped but not yet killed(this is important to remember), heavy processing should not be done in this part. Simply explained as, when the activity is launched in front of other activity, this method is invoked and the activity in bg is kept in pause.
Followed by onRestart(), when the activity is revoked from the background and followed by onDestroy() when the activity is closed or finished.
This is invoked when the activity is finished or the system itself is destroying it to acquire some space in the memory.
This was all about the LIFE CYCLE of the Activity in Android development.
Hope this answer is helpful for you and that, all that you needed to understand about this topic is relevant from my side.