我想我们一般在Service里想启动Activity一定会这样写:
这样写就会报错的:
ERROR/AndroidRuntime(7881): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
提示要加上FLAG_ACTIVITY_NEW_TASK,所以加上 intentv.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);这一行就可以了。
- Intent intentv = new Intent(Intent.ACTION_VIEW);
- intentv.setData(uri);
- intentv.putExtra("keepTitle", true);
- startActivity(intentv);
这样写就会报错的:
ERROR/AndroidRuntime(7881): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
提示要加上FLAG_ACTIVITY_NEW_TASK,所以加上 intentv.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);这一行就可以了。
本文介绍在Android Service中正确启动Activity的方法。通常情况下直接启动会遇到错误提示,文章给出了解决方案,即通过添加FLAG_ACTIVITY_NEW_TASK标志来避免异常。

502

被折叠的 条评论
为什么被折叠?



