/*** Retrieve a PendingIntent that will start a new activity, like calling* {@link Context#startActivity(Intent) Context.startActivity(Intent)}.* Note that the activity will be started outside of the context of an* existing activity, so you must use the {@link Intent#FLAG_ACTIVITY_NEW_TASK* Intent.FLAG_ACTIVITY_NEW_TASK} launch flag in the Intent.* 

class="note">For security reasons, the {@link android.content.Intent}* you supply here should almost always be an explicit intent,* that is specify an explicit component to be delivered to through* {@link Intent#setClass(android.content.Context, Class) Intent.setClass}

*/PendingIntent#getActivity

在 Android P 中,您不能从非 Activity 环境中启动 Activity,除非您传递 Intent 标志 FLAG_ACTIVITY_NEW_TASK。 如果您尝试在不传递此标志的情况下启动 Activity,则该 Activity 不会启动,系统会在日志中输出一则消息。

Android P之前的版本,从非Activity环境启动Activity,可以启动,但是会给出一条warning信息04-20 16:09:23.633 W/ActivityManager( 1783): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { cat=[3] flg=0x4800000 pkg=com.test.example cmp=com.test.example/.ui.MainActivity (has extras) }

FLAG_ACTIVITY_NEW_TASK: This flag can not be used when the caller is requesting a result from the activity being launched.
如果通过startActivityForResult启动一个FLAG_ACTIVITY_NEW_TASK的intent,则无法通过onActivityResult获取要启动的component的返回结果;新的intent activity一旦启动,则调用startActivityForResult的activity会立即回调进onActivityResult方法中,且resultCode=Activity.RESULT_CANCELED…

更多相关文章

  1. android3.1开发环境配置
  2. android的开发环境搭建
  3. Android 环境变量访问类
  4. Android开发环境的安装 Eclipse
  5. android(安卓) SDK 环境变量配置

随机推荐

  1. android的布局属性(转)
  2. 去掉android的屏幕上的title bar
  3. android emulator( android模拟器)
  4. Android设计模式系列
  5. android 全屏显示
  6. Android入门学习七:基本控件学习
  7. Material Design资料收集
  8. Android-TextView多行本文滚动轻松实现
  9. Android键盘自适应方法.
  10. android手机中图片的拖拉及浏览功能