{"id":804625,"date":"2024-07-29T00:15:05","date_gmt":"2024-07-28T16:15:05","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/804625.html"},"modified":"2024-07-29T00:15:09","modified_gmt":"2024-07-28T16:15:09","slug":"%e9%b8%bf%e8%92%99%e5%bc%80%e5%8f%91%e9%a1%b5%e9%9d%a2%e8%b7%b3%e8%bd%ac%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/804625.html","title":{"rendered":"\u9e3f\u8499\u5f00\u53d1\u9875\u9762\u8df3\u8f6c\u600e\u4e48\u5199"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25151643\/67723ba3-190e-41c4-9d86-d6c7b2bbc83e.webp\" alt=\"\u9e3f\u8499\u5f00\u53d1\u9875\u9762\u8df3\u8f6c\u600e\u4e48\u5199\" \/><\/p>\n<h2><strong>\u9e3f\u8499\u5f00\u53d1\u9875\u9762\u8df3\u8f6c\u600e\u4e48\u5199\uff1f<\/strong><\/h2>\n<p><p><strong>\u9e3f\u8499\u5f00\u53d1\u9875\u9762\u8df3\u8f6c\u4e3b\u8981\u6d89\u53ca\u4e24\u4e2a\u6838\u5fc3\u6982\u5ff5\uff1aAbility\u548cIntent\u3002<\/strong> \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u7406\u89e3\u9e3f\u8499OS\u4e2d\u7684Ability\u662f\u5177\u6709\u72ec\u7acb\u751f\u547d\u5468\u671f\u7684\u80fd\u529b\u6a21\u5757\uff0c\u5b83\u53ef\u4ee5\u662f\u9875\u9762\u3001\u670d\u52a1\u7b49\uff0c\u800cIntent\u5219\u662f\u9e3f\u8499OS\u4e2d\u7684\u4e00\u79cd\u6d88\u606f\u4f20\u9012\u673a\u5236\uff0c\u7528\u4e8e\u5b9e\u73b0Ability\u4e4b\u95f4\u7684\u901a\u4fe1\u548c\u8df3\u8f6c\u3002\u9e3f\u8499\u5f00\u53d1\u9875\u9762\u8df3\u8f6c\u7684\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\u521b\u5efa\u76ee\u6807Ability\u3001\u521b\u5efaIntent\u5bf9\u8c61\u3001\u8bbe\u7f6eIntent\u7684Action\u548cEntity\u3001\u4ee5\u53ca\u8c03\u7528startAbility\u65b9\u6cd5\u3002 <strong>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u8fdb\u884c\u8fd9\u4e9b\u6b65\u9aa4\u3002<\/strong><\/p>\n<\/p>\n<h2><strong>\u4e00\u3001\u521b\u5efa\u76ee\u6807Ability<\/strong><\/h2>\n<p><p>\u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\uff0c\u9875\u9762\u8df3\u8f6c\u7684\u6e90\u5934\u548c\u76ee\u6807\u90fd\u662fAbility\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u521b\u5efa\u6211\u4eec\u60f3\u8981\u8df3\u8f6c\u5230\u7684\u76ee\u6807Ability\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><h2>1.1 \u521b\u5efa\u76ee\u6807Ability\u7c7b<\/h2>\n<\/p>\n<p><p>\u5728\u4f60\u7684\u9879\u76ee\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Java\u7c7b\u6216Kotlin\u7c7b\uff0c\u8fd9\u4e2a\u7c7b\u9700\u8981\u7ee7\u627f\u81eaAbility\u6216\u8005\u5176\u5b50\u7c7b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">import ohos.aafwk.ability.Ability;<\/p>\n<p>import ohos.aafwk.content.Intent;<\/p>\n<p>public class TargetAbility extends Ability {<\/p>\n<p>    @Override<\/p>\n<p>    public void onStart(Intent intent) {<\/p>\n<p>        super.onStart(intent);<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>1.2 \u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6ce8\u518c\u76ee\u6807Ability<\/h2>\n<\/p>\n<p><p>\u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\uff0c\u6240\u6709\u7684Ability\u90fd\u9700\u8981\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u8fdb\u884c\u6ce8\u518c\u3002\u4f60\u9700\u8981\u6253\u5f00\u9879\u76ee\u7684config.json\u6587\u4ef6\uff0c\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u4f60\u7684\u76ee\u6807Ability\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-json\">{<\/p>\n<p>    &quot;module&quot;: {<\/p>\n<p>        &quot;package&quot;: &quot;&lt;\u4f60\u7684\u5305\u540d&gt;&quot;,<\/p>\n<p>        &quot;m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>nAbility&quot;: &quot;&lt;\u4f60\u7684\u4e3bAbility&gt;&quot;,<\/p>\n<p>        &quot;abilities&quot;: [<\/p>\n<p>            {<\/p>\n<p>                &quot;className&quot;: &quot;&lt;\u4f60\u7684\u76ee\u6807Ability\u7684\u5168\u7c7b\u540d&gt;&quot;,<\/p>\n<p>                &quot;type&quot;: &quot;page&quot;,<\/p>\n<p>                &quot;actions&quot;: [<\/p>\n<p>                    &quot;&lt;\u4f60\u7684Intent Action&gt;&quot;<\/p>\n<p>                ],<\/p>\n<p>                &quot;entities&quot;: [<\/p>\n<p>                    &quot;&lt;\u4f60\u7684Intent Entity&gt;&quot;<\/p>\n<p>                ]<\/p>\n<p>            }<\/p>\n<p>        ]<\/p>\n<p>    }<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e8c\u3001\u521b\u5efaIntent\u5bf9\u8c61<\/strong><\/h2>\n<p><p>\u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\uff0cIntent\u662f\u4e00\u79cd\u6d88\u606f\u4f20\u9012\u673a\u5236\uff0c\u7528\u4e8e\u5b9e\u73b0Ability\u4e4b\u95f4\u7684\u901a\u4fe1\u548c\u8df3\u8f6c\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Intent\u5bf9\u8c61\u6765\u5b9e\u73b0\u9875\u9762\u8df3\u8f6c\u3002<\/p>\n<\/p>\n<p><h2>2.1 \u521b\u5efaIntent\u5bf9\u8c61<\/h2>\n<\/p>\n<p><p>\u5728\u4f60\u7684\u6e90Ability\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Intent\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">Intent intent = new Intent();<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e09\u3001\u8bbe\u7f6eIntent\u7684Action\u548cEntity<\/strong><\/h2>\n<p><p>\u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\uff0cIntent\u7684Action\u548cEntity\u7528\u4e8e\u786e\u5b9a\u76ee\u6807Ability\u3002\u4f60\u9700\u8981\u5728\u4f60\u7684Intent\u5bf9\u8c61\u4e2d\u8bbe\u7f6e\u6b63\u786e\u7684Action\u548cEntity\uff0c\u4ee5\u786e\u5b9a\u4f60\u7684\u8df3\u8f6c\u76ee\u6807\u3002<\/p>\n<\/p>\n<p><h2>3.1 \u8bbe\u7f6eIntent\u7684Action<\/h2>\n<\/p>\n<p><p>\u5728\u4f60\u7684Intent\u5bf9\u8c61\u4e2d\uff0c\u8bbe\u7f6e\u4f60\u7684Action\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">intent.setAction(&quot;&lt;\u4f60\u7684Intent Action&gt;&quot;);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>3.2 \u8bbe\u7f6eIntent\u7684Entity<\/h2>\n<\/p>\n<p><p>\u5728\u4f60\u7684Intent\u5bf9\u8c61\u4e2d\uff0c\u8bbe\u7f6e\u4f60\u7684Entity\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">intent.setEntity(&quot;&lt;\u4f60\u7684Intent Entity&gt;&quot;);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u56db\u3001\u8c03\u7528startAbility\u65b9\u6cd5<\/strong><\/h2>\n<p><p>\u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528Ability\u7684startAbility\u65b9\u6cd5\u6765\u5b9e\u73b0\u9875\u9762\u8df3\u8f6c\u3002<\/p>\n<\/p>\n<p><h2>4.1 \u8c03\u7528startAbility\u65b9\u6cd5<\/h2>\n<\/p>\n<p><p>\u5728\u4f60\u7684\u6e90Ability\u4e2d\uff0c\u8c03\u7528startAbility\u65b9\u6cd5\uff0c\u4f20\u5165\u4f60\u7684Intent\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">startAbility(intent);<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u5c31\u53ef\u4ee5\u5b9e\u73b0\u9e3f\u8499\u5f00\u53d1\u9875\u9762\u8df3\u8f6c\u4e86\u3002\u540c\u65f6\uff0c\u4f60\u8fd8\u53ef\u4ee5\u901a\u8fc7Intent\u4f20\u9012\u6570\u636e\uff0c\u5b9e\u73b0\u9875\u9762\u4e4b\u95f4\u7684\u6570\u636e\u5171\u4eab\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>Q1: \u5982\u4f55\u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\u5b9e\u73b0\u9875\u9762\u8df3\u8f6c\uff1f<\/strong><\/p>\n<p>A1: \u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Navigator\u7ec4\u4ef6\u6765\u5b9e\u73b0\u9875\u9762\u8df3\u8f6c\u3002\u4f60\u53ef\u4ee5\u5728\u9700\u8981\u8df3\u8f6c\u7684\u7ec4\u4ef6\u4e0a\u6dfb\u52a0\u4e00\u4e2a\u70b9\u51fb\u4e8b\u4ef6\uff0c\u5e76\u5728\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u4e2d\u4f7f\u7528Navigator.push\u65b9\u6cd5\u6765\u8df3\u8f6c\u5230\u76ee\u6807\u9875\u9762\u3002<\/p>\n<p><strong>Q2: \u5982\u4f55\u4f20\u9012\u53c2\u6570\u8fdb\u884c\u9875\u9762\u8df3\u8f6c\uff1f<\/strong><\/p>\n<p>A2: \u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Navigator.push\u65b9\u6cd5\u7684secondBundle\u53c2\u6570\u6765\u4f20\u9012\u53c2\u6570\u8fdb\u884c\u9875\u9762\u8df3\u8f6c\u3002\u5728\u8df3\u8f6c\u5230\u76ee\u6807\u9875\u9762\u4e4b\u524d\uff0c\u4f60\u53ef\u4ee5\u5c06\u9700\u8981\u4f20\u9012\u7684\u53c2\u6570\u6dfb\u52a0\u5230secondBundle\u4e2d\uff0c\u7136\u540e\u5728\u76ee\u6807\u9875\u9762\u4e2d\u901a\u8fc7Navigator.getState\u65b9\u6cd5\u83b7\u53d6\u8fd9\u4e9b\u53c2\u6570\u3002<\/p>\n<p><strong>Q3: \u5982\u4f55\u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\u5b9e\u73b0\u9875\u9762\u8fd4\u56de\u529f\u80fd\uff1f<\/strong><\/p>\n<p>A3: \u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Navigator.pop\u65b9\u6cd5\u6765\u5b9e\u73b0\u9875\u9762\u8fd4\u56de\u529f\u80fd\u3002\u4f60\u53ef\u4ee5\u5728\u9700\u8981\u8fd4\u56de\u7684\u7ec4\u4ef6\u4e0a\u6dfb\u52a0\u4e00\u4e2a\u70b9\u51fb\u4e8b\u4ef6\uff0c\u5e76\u5728\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u4e2d\u4f7f\u7528Navigator.pop\u65b9\u6cd5\u6765\u8fd4\u56de\u5230\u4e0a\u4e00\u4e2a\u9875\u9762\u3002<\/p>\n<p><strong>Q4: \u5982\u4f55\u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\u5b9e\u73b0\u9875\u9762\u8df3\u8f6c\u52a8\u753b\u6548\u679c\uff1f<\/strong><\/p>\n<p>A4: \u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Navigator.push\u65b9\u6cd5\u7684animation\u53c2\u6570\u6765\u5b9e\u73b0\u9875\u9762\u8df3\u8f6c\u52a8\u753b\u6548\u679c\u3002\u4f60\u53ef\u4ee5\u5728\u8df3\u8f6c\u5230\u76ee\u6807\u9875\u9762\u65f6\uff0c\u6307\u5b9a\u4e0d\u540c\u7684\u52a8\u753b\u6548\u679c\uff0c\u4f8b\u5982fade\u3001slide\u7b49\u3002\u8fd9\u6837\u53ef\u4ee5\u4e3a\u7528\u6237\u63d0\u4f9b\u66f4\u52a0\u6d41\u7545\u548c\u5438\u5f15\u4eba\u7684\u9875\u9762\u5207\u6362\u4f53\u9a8c\u3002<\/p>\n<p><strong>Q5: \u5982\u4f55\u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\u5b9e\u73b0\u5e26\u8fd4\u56de\u6309\u94ae\u7684\u9875\u9762\u8df3\u8f6c\uff1f<\/strong><\/p>\n<p>A5: \u5728\u9e3f\u8499\u5f00\u53d1\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Navigator.push\u65b9\u6cd5\u7684navigationBar\u53c2\u6570\u6765\u5b9e\u73b0\u5e26\u8fd4\u56de\u6309\u94ae\u7684\u9875\u9762\u8df3\u8f6c\u3002\u4f60\u53ef\u4ee5\u8bbe\u7f6enavigationBar\u7684\u5c5e\u6027\uff0c\u4f8b\u5982title\u3001showBackButton\u7b49\uff0c\u6765\u5b9a\u5236\u5bfc\u822a\u680f\u7684\u6837\u5f0f\u548c\u529f\u80fd\u3002\u8fd9\u6837\u7528\u6237\u5728\u76ee\u6807\u9875\u9762\u5c31\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u8fd4\u56de\u6309\u94ae\u8fd4\u56de\u5230\u4e0a\u4e00\u4e2a\u9875\u9762\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u9e3f\u8499\u5f00\u53d1\u9875\u9762\u8df3\u8f6c\u600e\u4e48\u5199\uff1f \u9e3f\u8499\u5f00\u53d1\u9875\u9762\u8df3\u8f6c\u4e3b\u8981\u6d89\u53ca\u4e24\u4e2a\u6838\u5fc3\u6982\u5ff5\uff1aAbility\u548cIntent\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981 [&hellip;]","protected":false},"author":3,"featured_media":804637,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/804625"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=804625"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/804625\/revisions"}],"predecessor-version":[{"id":804642,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/804625\/revisions\/804642"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/804637"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=804625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=804625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=804625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}