关于startActivityforResult:Activity is launching as a new task, so cancelling activity result.”
近来,在使用startactivityforresult是加上了flags:intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 但是一启动Activity系统就回调了onActivityResult(int requestCode, int resultCode, Intent data) ,系统ActivityManager里有一段打印:W/ActivityManager( 4877): Activity is launching as a new task, so cancelling activity result. 查阅了相关的资料,有如下的解释:
requestCode值>=0,不然,startActivityForResult就变成了 startactivity
从SDK我们可以看到如下深奥的解释:http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
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.
从柯元旦的《Android 内核剖析》的第十章“Ams内部原理“10.1.3中有这样的一段话:请注意:SINGLE_TASK标识以及SINGLE_INSTANCE两个标识必须在r.result==0的条件中,即这两个标识只能用在startActivity()的方法中,而不能使用在startActivityForResult方法中。因为从Task的角度看,Android认为不同Task之间的Activity是不能传递数据的,所以不能使用NEW_TASK标识,但还是要调用forResult方法。