/*** 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. Android欢迎界面
  2. android开机启动代码
  3. Android(安卓)系统分析[1]
  4. H5与原生IOS交互
  5. Android在开机时自动启动一个应用程序
  6. Android(安卓)adb shell 启动java程序
  7. 启动android默认浏览器
  8. Android(安卓)Service
  9. Android(安卓)安装路径问题 -- 导致无法启动模拟器

随机推荐

  1. 编译Windows版Android(安卓)Emulator(Cup
  2. Android 使用SeekBar 变更屏幕亮度和声音
  3. android 制作自定义标题栏
  4. android:scaleType的使用
  5. Unity 对接 Android 打包编译 bug 总结之
  6. Android生命周期
  7. Android RelativeLayout用到的一些重要的
  8. android Service
  9. Android的一些例子
  10. Android EditText