3
回答
android生命周期问题
【腾讯云】校园拼团福利,1核2G服务器10元/月!>>>   

有2个活动,第一个MainActivity,第二个DisplayMessageActivity。

有如下操作:

1.Main活动按钮启动Display活动,生命周期如下,没问题。


  1. 11-15 02:56:16.904: D/MainActivity(1652): On Pause
  2. 11-15 02:56:16.932: D/DisplayMessageActivity(1652): On Create
  3. 11-15 02:56:17.004: D/DisplayMessageActivity(1652): On Start
  4. 11-15 02:56:17.004: D/DisplayMessageActivity(1652): On Resume
  5. 11-15 02:56:17.656: D/MainActivity(1652): On Stop

2.在Display活动按下顶部actionBar的导航回退,生命周期如下:

  1. 11-15 02:57:27.788: D/DisplayMessageActivity(1652): On Pause
  2. 11-15 02:57:27.808: D/MainActivity(1652): On Destory
  3. 11-15 02:57:27.880: D/MainActivity(1652): On Create
  4. 11-15 02:57:27.880: D/MainActivity(1652): On Start
  5. 11-15 02:57:27.880: D/MainActivity(1652): On Resume
  6. 11-15 02:57:31.104: D/DisplayMessageActivity(1652): On Stop
  7. 11-15 02:57:31.104: D/DisplayMessageActivity(1652): On Destory
3.接着重复第一个操作,在Display中按下模拟器的回退按钮(back),生命周期如下:
  1. 11-15 02:58:50.908: D/DisplayMessageActivity(1652): On Pause
  2. 11-15 02:58:50.912: D/MainActivity(1652): onActivityResult First Param:123 //传参
  3. 11-15 02:58:50.912: D/MainActivity(1652): onActivityResult Secenod Param:456 //传参 
  4. 11-15 02:58:50.912: D/MainActivity(1652): On Restart
  5. 11-15 02:58:50.912: D/MainActivity(1652): On Start
  6. 11-15 02:58:50.912: D/MainActivity(1652): On Resume
  7. 11-15 02:58:52.300: D/DisplayMessageActivity(1652): On Stop
  8. 11-15 02:58:52.300: D/DisplayMessageActivity(1652): On Destory

在Main onActivityResult回调方法打印出requestCode和resultCode

问题,为什么2和3操作的周期不一样,并且在2操作中销毁重现创建活动,取不到返回数据。而3操作中却不一样?

求解答谢谢



举报
CoderLeon
发帖于3年前 3回/117阅
顶部