简体   繁体   中英

activity life cycle Android

I have read several posts on here and elsewhere about the life cycle but I'm still confused. What do we store in the onpause, how do we store it and how do you recall it in the onresume Method. Any more info and if possible a detailed example would be greatly appreciated.

Is this what you mean

在此输入图像描述

For further explanation

  • onCreate(Bundle) is where you initialize your activity. Most importantly, here you will usually call setContentView(int) with a layout resource defining your UI, and using findViewById(int) to retrieve the widgets in that UI that you need to interact with programmatically.
  • onPause() is where you deal with the user leaving your activity. Most importantly, any changes made by the user should at this point be committed (usually to the ContentProvider holding the data).
  • onResume() Called after onRestoreInstanceState(Bundle), onRestart(), or onPause(), for your activity to start interacting with the user. This is a good place to begin animations, open exclusive-access devices (such as the camera), etc.
  • onDestroy() Perform any final cleanup before an activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.

You can see it all here . Hope it helps.

Depends on what you are using. Things like OpenGL and the camera app will require you take certain action whenever the application life-cycle changes. For example, resources need to be freed when on pause is called, then u allocate them again when on resume is called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM