CocoSnake

 

The Window was lost......

看了很久还是对LaunchMode有点晕,今天遇到一个问题:

Service收到事件A1 Launch ActivityB, 然后Service收到事件A2 结束ActivityB.

为了实现这个功能在ActivityB中调用了OnNewIntent() 在其中执行finish(), 并且把B的LaunchMode设置为SingleTask.

结果运行中发现,如果在Launch B以后用户按了Back Key, 这个Activity就不复存在了, 等到Service发送New Intent到B的时候

原来的Activity已经不存在了, 所以启动了一个新的Activity, 并且调用的OnCreate(), 而不是OnNewIntent().

今天又重新看了一眼老罗的Blog, 算是温习一下。

在官方的文档中我们可以看到:

void onNewIntent(Intentintent)
This is called for activities that set launchMode to "singleTop" in their package, or if a client used the FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent).

还是singleTop比较靠谱。

并且还有这样一段描述:

As shown in the table above, standard is the default mode and is appropriate for most types of activities. SingleTop is also a common and useful launch mode for many types of activities. The other modes — singleTask and singleInstance —are not appropriate for most applications, since they result in an interaction model that is likely to be unfamiliar to users and is very different from most other applications.
Regardless of the launch mode that you choose, make sure to test the usability of the activity during launch and when navigating back to it from other activities and tasks using the BACK key.

用SingleTast和SingleInstance的时候一定要自己试一试啊

 

posted on 2012-03-30 17:40  CocoSnake  阅读(916)  评论(0编辑  收藏  举报

导航