{"id":725,"date":"2023-02-26T15:35:59","date_gmt":"2023-02-26T07:35:59","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=725"},"modified":"2023-04-29T17:13:03","modified_gmt":"2023-04-29T09:13:03","slug":"android-solve-cpu-sleep-timer-not-executing","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/android-solve-cpu-sleep-timer-not-executing\/","title":{"rendered":"Android\u89e3\u51b3CPU\u4f11\u7720Timer\u4e0d\u6267\u884c"},"content":{"rendered":"<p>\u5728\u5f00\u53d1\u4e2d\uff0c\u6709\u65f6\u6211\u4eec\u9700\u8981\u5728\u540e\u53f0\u5faa\u73af\u6267\u884c\u4e00\u4e9b\u64cd\u4f5c\uff08\u6bd4\u5982\uff1a\u5b9a\u65f6\u4efb\u52a1\u3001\u5373\u65f6\u901a\u8baf\u5fc3\u8df3\u5305\u7684\u53d1\u9001\u7b49\uff09<\/p>\n<p>\u7ed3\u679c\u53d1\u73b0\u624b\u673a\u53d1\u751f\u9501\u5c4f\u7684\u64cd\u4f5c\u540e\uff0cCPU\u8fdb\u5165\u4f11\u7720\uff0c\u5bfc\u81f4TimerTask\u4e0d\u5de5\u4f5c\uff0c\u76f4\u5230\u89e3\u9501\u5c4f\u5e55CPU\u88ab\u5524\u9192\u540e\uff0cTimer\u624d\u7ee7\u7eed\u6267\u884c<\/p>\n<p><!-- more --><\/p>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p>\uff081\uff09\u83b7\u53d6\u7535\u6e90\u9501\uff0c\u8ba9CPU\u4e0d\u4f11\u7720\uff08\u8017\u7535\u4e25\u91cd\uff09<br \/>\n\uff082\uff09\u4f7f\u7528AlarmManager\u4ee3\u66ffTimer<\/p>\n<p>\u8bf4\u660e\uff1aAndroid\u624b\u673a\u6709\u4e24\u4e2a\u5904\u7406\u5668\uff0c\u4e00\u4e2a\u53ebApplication Processor\uff08AP\uff09\uff0c\u4e00\u4e2a\u53ebBaseband Processor\uff08BP\uff09\u3002AP\u662fARM\u67b6\u6784\u7684\u5904\u7406\u5668\uff0c\u7528\u4e8e\u8fd0\u884cLinux+Android\u7cfb\u7edf\uff1bBP\u7528\u4e8e\u8fd0\u884c\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf\uff08RTOS\uff09\u3002AlarmManager \u662f Android \u7cfb\u7edf\u5c01\u88c5\u7684\u7528\u4e8e\u7ba1\u7406 RTC \u7684\u6a21\u5757\uff0cRTC (Real Time Clock) \u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u786c\u4ef6\u65f6\u949f\uff0c\u53ef\u4ee5\u5728 CPU \u4f11\u7720\u65f6\u6b63\u5e38\u8fd0\u884c\uff0c\u5728\u9884\u8bbe\u7684\u65f6\u95f4\u5230\u8fbe\u65f6\uff0c\u901a\u8fc7\u4e2d\u65ad\u5524\u9192 CPU\u3002<\/p>\n<p>AlarmManager\u4f7f\u7528\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-java\">Intent intent = new Intent();\nintent.setAction(&quot;&quot;);\nPendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0);\nAlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);\nalarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 1000 * 10, sender);<\/code><\/pre>\n<p>\u6e05\u5355\u6587\u4ef6\u6ce8\u518c\uff1a<\/p>\n<pre><code class=\"language-xml\">&lt;receiver android:name=&quot;&quot;&gt;\n    &lt;intent-filter&gt;\n        &lt;action android:name=&quot;&quot; \/&gt;\n    &lt;\/intent-filter&gt;\n&lt;\/receiver&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5f00\u53d1\u4e2d\uff0c\u6709\u65f6\u6211\u4eec\u9700\u8981\u5728\u540e\u53f0\u5faa\u73af\u6267\u884c\u4e00\u4e9b\u64cd\u4f5c\uff08\u6bd4\u5982\uff1a\u5b9a\u65f6\u4efb\u52a1\u3001\u5373\u65f6\u901a\u8baf\u5fc3\u8df3\u5305\u7684\u53d1\u9001\u7b49\uff09 \u7ed3\u679c\u53d1\u73b0\u624b\u673a\u53d1\u751f\u9501\u5c4f\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[213],"tags":[214],"class_list":["post-725","post","type-post","status-publish","format-standard","hentry","category-android-performance","tag-214"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/725","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=725"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/725\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}