{"id":2186,"date":"2023-03-29T21:51:56","date_gmt":"2023-03-29T13:51:56","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2186"},"modified":"2023-05-01T11:25:50","modified_gmt":"2023-05-01T03:25:50","slug":"android-p-new-feature-force-flag-execution-activity-new-task-requirements","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/29\/android-p-new-feature-force-flag-execution-activity-new-task-requirements\/","title":{"rendered":"Android P\u65b0\u7279\u6027\uff1a\u5f3a\u5236\u6267\u884c FLAG_ACTIVITY_NEW_TASK \u8981\u6c42"},"content":{"rendered":"<p>\u5728 Android P \u4e2d\uff0c\u4e0d\u80fd\u4ece\u975e Activity \u73af\u5883\u4e2d\u542f\u52a8 Activity\uff0c\u9664\u975e\u4f20\u9012 Intent \u6807\u5fd7 <code>FLAG_ACTIVITY_NEW_TASK<\/code>\u3002 \u5982\u679c\u60a8\u5c1d\u8bd5\u5728\u4e0d\u4f20\u9012\u6b64\u6807\u5fd7\u7684\u60c5\u51b5\u4e0b\u542f\u52a8 Activity\uff0c\u5219\u8be5 Activity \u4e0d\u4f1a\u542f\u52a8\uff0c\u7cfb\u7edf\u4f1a\u5728\u65e5\u5fd7\u4e2d\u8f93\u51fa\u4e00\u5219\u6d88\u606f\uff1a<\/p>\n<pre><code>Calling startActivity() from outside of an Activity  context requires the  \nFLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?<\/code><\/pre>\n<p>\u89e3\u51b3\u65b9\u5f0f\uff1a<\/p>\n<pre><code>Intent intent = new Intent(context, XXXActivity.class);\nif (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.P) {\n    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n}\ncontext.startActivity(intent);<\/code><\/pre>\n<p>\u5982\u679c\u901a\u8fc7<code>startActivityForResult<\/code>\u542f\u52a8\u4e00\u4e2a<code>FLAG_ACTIVITY_NEW_TASK<\/code>\u7684intent\uff0c\u5219\u65e0\u6cd5\u901a\u8fc7<code>onActivityResult<\/code>\u83b7\u53d6\u8981\u542f\u52a8\u7684component\u7684\u8fd4\u56de\u7ed3\u679c\u3002\u65b0\u7684intent activity\u4e00\u65e6\u542f\u52a8\uff0c\u5219\u8c03\u7528<code>startActivityForResult<\/code>\u7684activity\u4f1a\u7acb\u5373\u56de\u8c03\u8fdbonActivityResult\u65b9\u6cd5\u4e2d\uff0c\u4e14<code>resultCode=Activity.RESULT_CANCELED<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Android P \u4e2d\uff0c\u4e0d\u80fd\u4ece\u975e Activity \u73af\u5883\u4e2d\u542f\u52a8 Activity\uff0c\u9664\u975e\u4f20\u9012 Intent  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[325],"tags":[],"class_list":["post-2186","post","type-post","status-publish","format-standard","hentry","category-android-adaptation"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2186"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2186\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}