一个app中包括多中启动方式 singletask singleInstant等启动这个app以后 点home键暂时退出之后再点桌面图标 or 长按home键 恢复程序这两种操作的机制有什么不同?

解决方案 »

  1.   

    一样的,都是从栈里面取出之前的activity 呈现
      

  2.   

    好像还是有区别的,据说设为singleInstance后,桌面启动走onNewIntent,长按启动走onResume
      

  3.   

    我试验发现是这样的 长按home键从哪个acitvity退出从哪回  桌面点进去是回主栈的栈顶
      

  4.   

    如果当前从Home键点击退出去的Activity为singleInstance模式
      当长按home键进去的时候,走的是onRestart()-onStart()-onResume()的生命周期
      而点击图标走的是onNewIntent()-onRestart()-onStart()-onResume()-...
    对于onNewIntent使用场合,看API这句:
    This is called for activities that set launchMode to "singleTop" in
    their package, or if a client used the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP}
    flag when calling {@link #startActivity}.  In either case, when the
    activity is re-launched while at the top of the activity stack instead
    of a new instance of the activity being started, onNewIntent() will be
    called on the existing instance with the Intent that was used to
    re-launch it.