Intent启动activity之FLAG_ACTIVITY相关行为使用技巧

实验方案1:

Main1Activity调用Main2Activity,Main2Activity调用Main3Activity,Main3Activity调用Main1Activity,然后依此返回看结果


1. FLAG_ACTIVITY_NEW_TASK:

04-10 14:26:05.793: I/System.out(20278): com.example.a1.Main1Activity@1887d7dMain1Activity onCreate
04-10 14:26:18.626: I/System.out(20278): com.example.a1.Main2Activity@a16ffa5Main2Activity onCreate
04-10 14:26:21.707: I/System.out(20278): com.example.a1.Main3Activity@4801c15Main3Activity onCreate

04-10 14:26:23.056: I/System.out(20278): com.example.a1.Main1Activity@42475fcMain1Activity onCreate

返回

04-10 14:26:25.121: I/System.out(20278): com.example.a1.Main1Activity@42475fcMain1Activity onDestroy
04-10 14:26:25.889: I/System.out(20278): com.example.a1.Main3Activity@4801c15Main3Activity onDestroy
04-10 14:26:26.521: I/System.out(20278): com.example.a1.Main2Activity@a16ffa5Main2Activity onDestroy
04-10 14:26:27.138: I/System.out(20278): com.example.a1.Main1Activity@1887d7dMain1Activity onDestroy


2. FLAG_ACTIVITY_SINGLE_TOP

04-10 14:27:16.256: I/System.out(20734): com.example.a1.Main1Activity@1887d7dMain1Activity onCreate
04-10 14:27:29.947: I/System.out(20734): com.example.a1.Main2Activity@a16ffa5Main2Activity onCreate
04-10 14:27:31.341: I/System.out(20734): com.example.a1.Main3Activity@4801c15Main3Activity onCreate

04-10 14:27:32.592: I/System.out(20734): com.example.a1.Main1Activity@42475fcMain1Activity onCreate

返回

04-10 14:27:38.101: I/System.out(20734): com.example.a1.Main1Activity@42475fcMain1Activity onDestroy
04-10 14:27:39.090: I/System.out(20734): com.example.a1.Main3Activity@4801c15Main3Activity onDestroy
04-10 14:27:39.773: I/System.out(20734): com.example.a1.Main2Activity@a16ffa5Main2Activity onDestroy
04-10 14:27:40.451: I/System.out(20734): com.example.a1.Main1Activity@1887d7dMain1Activity onDestroy



3. FLAG_ACTIVITY_CLEAR_TOP

04-10 14:29:42.204: I/System.out(21268): com.example.a1.Main1Activity@1887d7dMain1Activity onCreate
04-10 14:29:45.014: I/System.out(21268): com.example.a1.Main2Activity@873f99cMain2Activity onCreate
04-10 14:29:45.837: I/System.out(21268): com.example.a1.Main3Activity@df701ccMain3Activity onCreate
04-10 14:29:47.532: I/System.out(21268): com.example.a1.Main2Activity@873f99cMain2Activity onDestroy
04-10 14:29:47.541: I/System.out(21268): com.example.a1.Main1Activity@1887d7dMain1Activity onDestroy
04-10 14:29:47.563: I/System.out(21268): com.example.a1.Main1Activity@c613485Main1Activity onCreate

04-10 14:29:47.831: I/System.out(21268): com.example.a1.Main3Activity@df701ccMain3Activity onDestroy

返回

04-10 14:29:57.562: I/System.out(21268): com.example.a1.Main1Activity@c613485Main1Activity onDestroy



4.FLAG_ACTIVITY_REORDER_TO_FRONT

04-10 14:35:39.421: I/System.out(22240): com.example.a1.Main1Activity@1887d7dMain1Activity onCreate
04-10 14:35:42.197: I/System.out(22240): com.example.a1.Main2Activity@873f99cMain2Activity onCreate
04-10 14:35:46.156: I/System.out(22240): com.example.a1.Main3Activity@df701ccMain3Activity onCreate

重新调用1887d7dMain1Activity的onStart

返回

04-10 14:36:07.917: I/System.out(22240): com.example.a1.Main1Activity@1887d7dMain1Activity onDestroy
04-10 14:36:08.378: I/System.out(22240): com.example.a1.Main3Activity@df701ccMain3Activity onDestroy
04-10 14:36:08.969: I/System.out(22240): com.example.a1.Main2Activity@873f99cMain2Activity onDestroy



实验方案2:

Main1Activity调用Main1Activity,然后依此返回看结果


1. FLAG_ACTIVITY_NEW_TASK:

04-10 14:15:20.893: I/System.out(17454): com.example.a1.Main1Activity@1887d7dMain1Activity onCreate
04-10 14:15:24.110: I/System.out(17454): com.example.a1.Main1Activity@217550fMain1Activity onCreate

返回
04-10 14:15:26.995: I/System.out(17454): com.example.a1.Main1Activity@217550fMain1Activity onDestroy
04-10 14:15:28.063: I/System.out(17454): com.example.a1.Main1Activity@1887d7dMain1Activity onDestroy


2. FLAG_ACTIVITY_SINGLE_TOP:

04-10 14:16:53.263: I/System.out(17992): com.example.a1.Main1Activity@1887d7dMain1Activity onCreate

返回

04-10 14:16:59.930: I/System.out(17992): com.example.a1.Main1Activity@1887d7dMain1Activity onDestroy


3. FLAG_ACTIVITY_CLEAR_TOP:

04-10 14:09:52.882: I/System.out(16952): com.example.a1.Main1Activity@1887d7dMain1Activity onCreate
04-10 14:09:58.800: I/System.out(16952): com.example.a1.Main1Activity@217550fMain1Activity onCreate
04-10 14:09:59.014: I/System.out(16952): com.example.a1.Main1Activity@1887d7dMain1Activity onDestroy

返回
04-10 14:10:02.967: I/System.out(16952): com.example.a1.Main1Activity@217550fMain1Activity onDestroy


4.FLAG_ACTIVITY_REORDER_TO_FRONT:

04-10 14:18:38.925: I/System.out(18498): com.example.a1.Main1Activity@1887d7dMain1Activity onCreate

返回
04-10 14:18:44.889: I/System.out(18498): com.example.a1.Main1Activity@1887d7dMain1Activity onDestroy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值