开发者

android activity life cycle: can an internal app activity be reopened if process is killed?

I have an app with several activities, which in order to function properly need to come to life after the main activity does (because the main activity initialize many things, for example lets the user selects the current project..).

Now, if the user is editing a project in the app, then goes to another app and for low memory my app is killed, when the user presses the back button (and get to the last closed activity) what happens?

My app will launch again, but will it start from the main activity or from the last opened one (as it would if it 开发者_Python百科hadn't been killed yet)?

Thanks.. it's quite difficult to really get this life cycle for me..


The last activity of your app will be recreated and the onCreate method called as though it was brand new.

The difference is, you need to override onSaveInstanceState and save your state there.

When onCreate is called you can tell if your activity is really new or coming back from being killed by checking for the presence of your data's keys.

See: onSaveInstanceState


You can override the onDestroy() method in your activities (the method called when memory is needed and Android "kills" the app) and see what happens. AFAICT the platform kills the process altogether meaning all threads and activities. I'm guessing it's not that granular.

Hope it helped! JQCorreia

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜