import{_ as s,o as n,c as a,a as l}from"./app.f643a53b.js";const e={},p=l(`<h1 id="\u5BBF\u4E3B\u751F\u547D\u5468\u671F\u6269\u5C55" tabindex="-1"><a class="header-anchor" href="#\u5BBF\u4E3B\u751F\u547D\u5468\u671F\u6269\u5C55" aria-hidden="true">#</a> \u5BBF\u4E3B\u751F\u547D\u5468\u671F\u6269\u5C55</h1><blockquote><p>\u8FD9\u662F\u4E00\u4E2A\u81EA\u52A8 Hook \u5BBF\u4E3B APP \u751F\u547D\u5468\u671F\u7684\u6269\u5C55\u529F\u80FD\u3002</p></blockquote><h2 id="\u76D1\u542C\u751F\u547D\u5468\u671F" tabindex="-1"><a class="header-anchor" href="#\u76D1\u542C\u751F\u547D\u5468\u671F" aria-hidden="true">#</a> \u76D1\u542C\u751F\u547D\u5468\u671F</h2><blockquote><p>\u901A\u8FC7\u81EA\u52A8\u5316 Hook \u5BBF\u4E3B APP \u7684\u751F\u547D\u5468\u671F\u65B9\u6CD5\uFF0C\u6765\u5B9E\u73B0\u76D1\u542C\u529F\u80FD\u3002</p></blockquote><p>\u6211\u4EEC\u9700\u8981\u76D1\u542C\u5BBF\u4E3B <code>Application</code> \u7684\u542F\u52A8\u548C\u751F\u547D\u5468\u671F\u65B9\u6CD5\uFF0C\u53EA\u9700\u8981\u4F7F\u7528\u4EE5\u4E0B\u65B9\u5F0F\u5B9E\u73B0\u3002</p><blockquote><p>\u793A\u4F8B\u5982\u4E0B</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">loadApp(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.example.demo&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// \u6CE8\u518C\u751F\u547D\u5468\u671F\u76D1\u542C</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// \u53EF\u9009\u53C2\u6570\uFF1A\u4F60\u53EF\u4EE5\u8BBE\u7F6E isOnFailureThrowToApp = false \u4F7F\u5F97\u5176\u4E2D\u7684\u5F02\u5E38\u4E0D\u4F1A\u629B\u51FA\u7ED9\u5BBF\u4E3B\u9632\u6B62\u5BBF\u4E3B\u5D29\u6E83\uFF0C\u9ED8\u8BA4\u4E3A true</span></span>
<span class="line"><span style="color:#ADBAC7;">    onAppLifecycle(isOnFailureThrowToApp </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">true</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// \u4F60\u53EF\u4EE5\u5728\u8FD9\u91CC\u5B9E\u73B0 Application \u4E2D\u7684\u751F\u547D\u5468\u671F\u65B9\u6CD5\u76D1\u542C</span></span>
<span class="line"><span style="color:#ADBAC7;">        attachBaseContext { baseContext, hasCalledSuper </span><span style="color:#F47067;">-&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// \u901A\u8FC7\u5224\u65AD hasCalledSuper \u6765\u786E\u5B9A\u662F\u5426\u5DF2\u6267\u884C super.attachBaseContext(base) \u65B9\u6CD5</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">        onCreate {</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// \u901A\u8FC7 this \u5F97\u5230\u5F53\u524D Application \u5B9E\u4F8B</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">        onTerminate {</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// \u901A\u8FC7 this \u5F97\u5230\u5F53\u524D Application \u5B9E\u4F8B</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">        onLowMemory {</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// \u901A\u8FC7 this \u5F97\u5230\u5F53\u524D Application \u5B9E\u4F8B</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">        onTrimMemory { self, level </span><span style="color:#F47067;">-&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// \u53EF\u5728\u8FD9\u91CC\u5224\u65AD APP \u662F\u5426\u5DF2\u5207\u6362\u5230\u540E\u53F0</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#F47067;">if</span><span style="color:#ADBAC7;"> (level </span><span style="color:#F47067;">==</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">ComponentCallbacks2</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">TRIM_MEMORY_UI_HIDDEN</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">                </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">        onConfigurationChanged { self, config </span><span style="color:#F47067;">-&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">\u5C0F\u63D0\u793A</p><p>\u66F4\u591A\u529F\u80FD\u8BF7\u53C2\u8003 <a href="../public/com/highcapable/yukihookapi/hook/param/PackageParam#applifecycle-class">AppLifecycle</a>\u3002</p></div><h2 id="\u6CE8\u518C\u7CFB\u7EDF\u5E7F\u64AD" tabindex="-1"><a class="header-anchor" href="#\u6CE8\u518C\u7CFB\u7EDF\u5E7F\u64AD" aria-hidden="true">#</a> \u6CE8\u518C\u7CFB\u7EDF\u5E7F\u64AD</h2><blockquote><p>\u901A\u8FC7 <code>Application.onCreate</code> \u65B9\u6CD5\u6CE8\u518C\u7CFB\u7EDF\u5E7F\u64AD\uFF0C\u6765\u5B9E\u73B0\u5BF9\u7CFB\u7EDF\u5E7F\u64AD\u7684\u76D1\u542C\u3002</p></blockquote><p>\u6211\u4EEC\u8FD8\u53EF\u4EE5\u5728\u5BBF\u4E3B <code>Application</code> \u4E2D\u6CE8\u518C\u7CFB\u7EDF\u5E7F\u64AD\u3002</p><blockquote><p>\u793A\u4F8B\u5982\u4E0B</p></blockquote><div class="language-kotlin ext-kt line-numbers-mode"><pre class="shiki" style="background-color:#22272e;"><code><span class="line"><span style="color:#ADBAC7;">loadApp(name </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;com.example.demo&quot;</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// \u6CE8\u518C\u751F\u547D\u5468\u671F\u76D1\u542C</span></span>
<span class="line"><span style="color:#ADBAC7;">    onAppLifecycle {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// \u6CE8\u518C\u7528\u6237\u89E3\u9501\u65F6\u7684\u5E7F\u64AD\u76D1\u542C</span></span>
<span class="line"><span style="color:#ADBAC7;">        registerReceiver(</span><span style="color:#F69D50;">Intent</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">ACTION_USER_PRESENT</span><span style="color:#ADBAC7;">) { context, intent </span><span style="color:#F47067;">-&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// \u6CE8\u518C\u591A\u4E2A\u5E7F\u64AD\u76D1\u542C\uFF0C\u4F1A\u540C\u65F6\u56DE\u8C03\u591A\u6B21</span></span>
<span class="line"><span style="color:#ADBAC7;">        registerReceiver(</span><span style="color:#F69D50;">Intent</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">ACTION_PACKAGE_CHANGED</span><span style="color:#ADBAC7;">, </span><span style="color:#F69D50;">Intent</span><span style="color:#ADBAC7;">.</span><span style="color:#F69D50;">ACTION_TIME_TICK</span><span style="color:#ADBAC7;">) { context, intent </span><span style="color:#F47067;">-&gt;</span></span>
<span class="line"><span style="color:#ADBAC7;">            </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">\u5C0F\u63D0\u793A</p><p>\u66F4\u591A\u529F\u80FD\u8BF7\u53C2\u8003 <a href="../public/com/highcapable/yukihookapi/hook/param/PackageParam#applifecycle-class">AppLifecycle</a>\u3002</p></div>`,14),o=[p];function c(i,r){return n(),a("div",null,o)}const d=s(e,[["render",c],["__file","host-lifecycle.html.vue"]]);export{d as default};
