当前位置:首页 > 未命名 > 正文内容

Activity life cycle and launch mode

u3blog8年前 (2016-03-15)未命名195

Activity life cycle

Activity's life cycle is well know, it can be summarize by below pic It is divided into two cases, normal and exception life cycle

Normal life cycle

It's the life cycle show in the pic's AXES, very simple and easy to know.

one question,onStart onResume, onPause onStop function looks very similar, what's the different with them?

The different is, onStart and onPause is invoked when activity visible and not visible, onResume and onStop is invoked when the activity is in the front and not front.

Exception life cycle

Mainly is when activity killed in background and restart life cycle, if not set the onConfigChange after killed activity will invoke onSaveInstanceState to save some status such as text. After restart, will invoke onRestyoreInstanceState to recover it's saved info. When the onconfigchange set on the manifest, after killed will invoke onConfigrationChanged to save info, so we can set onConfigCHnage to different case such as rotate or other.

Activity launch mode

there are four launch mode stand stand mode singleTask only one instance exist in task stack singleTop if not have in top of task stack, create new, if not will not create. singleInstance create a new task and put the new instance in it.

TaskAffinity

when a new instance create, will find the same package name app to enjoin it, for more detail, you can see below post 关于TaskAffinity属性的作用

set FLAG in code to set Activity launch mode

We can also set FLAG in code to set activity launch mode FLAG_ACTIVITY_NEW_TASK equal singletask FLAG_ACTIVITY_SINGLE_TOP equal singleTop FLAG_ACTIVITY_CLEAR_TOP equal singletask FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS this activity not show in recent app

ACTION and CATEGORY match rules

ACTION must have exist to match,category can not have, system will auto add a DEFAULT category.

扫描二维码推送至手机访问。

版权声明:本文由u3blog发布,如需转载请注明出处。

本文链接:https://u3blog.xyz/?id=285

分享给朋友:

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。