{"id":47772,"date":"2024-12-02T15:34:14","date_gmt":"2024-12-02T07:34:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47772\/"},"modified":"2024-12-02T15:34:14","modified_gmt":"2024-12-02T07:34:14","slug":"android-fragment-%e5%88%87%e6%8d%a2%e5%af%bc%e8%87%b4%e5%ae%9a%e6%97%b6%e5%99%a8%e9%97%aa%e9%80%80%ef%bc%9f%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3task-%e5%b7%b2%e5%ae%89%e6%8e%92%e6%88%96","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47772\/","title":{"rendered":"## Android Fragment \u5207\u6362\u5bfc\u81f4\u5b9a\u65f6\u5668\u95ea\u9000\uff1f\u5982\u4f55\u89e3\u51b3\u201cTask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88\u201d\u9519\u8bef\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>## Android Fragment \u5207\u6362\u5bfc\u81f4\u5b9a\u65f6\u5668\u95ea\u9000\uff1f\u5982\u4f55\u89e3\u51b3\u201cTask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88\u201d\u9519\u8bef\uff1f<\/h1>\n<p>\u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a## Android Fragment \u5207\u6362\u5bfc\u81f4\u5b9a\u65f6\u5668\u95ea\u9000\uff1f\u5982\u4f55\u89e3\u51b3\u201cTask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88\u201d\u9519\u8bef\uff1f\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241029\/17302077506720e0069d98a.jpg\" class=\"aligncenter\" title=\"## Android Fragment \u5207\u6362\u5bfc\u81f4\u5b9a\u65f6\u5668\u95ea\u9000\uff1f\u5982\u4f55\u89e3\u51b3\u201cTask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88\u201d\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"## Android Fragment \u5207\u6362\u5bfc\u81f4\u5b9a\u65f6\u5668\u95ea\u9000\uff1f\u5982\u4f55\u89e3\u51b3\u201cTask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88\u201d\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>android fragment \u5207\u6362\u5bfc\u81f4\u5b9a\u65f6\u5668\u95ea\u9000\uff1atask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88<\/strong><\/p>\n<p>\u5728 android \u5e94\u7528\u4e2d\uff0cfragment \u662f\u7528\u6765\u7ba1\u7406 ui \u7ec4\u4ef6\u7684\uff0c\u5728 fragment \u751f\u547d\u5468\u671f\u4e2d\uff0c\u6839\u636e fragment \u7684\u53ef\u89c1\u6027\u4f1a\u89e6\u53d1\u4e0d\u540c\u7684\u56de\u8c03\u65b9\u6cd5\uff0c\u5982 onstart() \u548c onstop()\u3002<\/p>\n<p>\u5728\u4f7f\u7528\u5b9a\u65f6\u5668\u65f6\uff0c\u901a\u5e38\u5728 onstart() \u4e2d\u5b89\u6392\u5b9a\u65f6\u5668\u4efb\u52a1\uff0c\u5728 onstop() \u4e2d\u53d6\u6d88\u5b9a\u65f6\u5668\u4efb\u52a1\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4ece\u53e6\u4e00\u4e2a fragment \u8fd4\u56de\u6b64 fragment \u540e\uff0c\u5e94\u7528\u53ef\u80fd\u4f1a\u95ea\u9000\uff0c\u5e76\u663e\u793a\u9519\u8bef\u6d88\u606f\u201ctask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88\u201d\u3002<\/p>\n<p>\u6b64\u9519\u8bef\u7684\u539f\u56e0\u662f\uff0ctimertask \u53ea\u80fd\u7531 timer \u8c03\u5ea6\u4e00\u6b21\u3002\u5728 onstart() \u4e2d\u91cd\u65b0\u521b\u5efa\u4e00\u4e2a timer \u4e0d\u4f1a\u89e3\u51b3\u95ee\u9898\uff0c\u56e0\u4e3a\u4f60\u5b9e\u9645\u4e0a\u9700\u8981\u91cd\u65b0\u521b\u5efa task\u3002<\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<p>\u5728 onstart() \u4e2d\uff0c\u4e0d\u8981\u91cd\u65b0\u521b\u5efa timer\u3002<br \/>\u76f8\u53cd\uff0c\u521b\u5efa\u5e76\u5b89\u6392\u4e00\u4e2a\u65b0 task\u3002<br \/>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>    @Override\n    public void onStart() {\n        super.onStart();\n        task = new TimerTask() {\n            @Override\n            public void run() {\n                \/\/ \u6267\u884c\u4efb\u52a1\u4ee3\u7801\n            }\n        };\n        timer.schedule(task, 0, 10000);\n    }<\/pre>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a## Android Fragment \u5207\u6362\u5bfc\u81f4\u5b9a\u65f6\u5668\u95ea\u9000\uff1f\u5982\u4f55\u89e3\u51b3\u201cTask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88\u201d\u9519\u8bef\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>## Android Fragment \u5207\u6362\u5bfc\u81f4\u5b9a\u65f6\u5668\u95ea\u9000\uff1f\u5982\u4f55\u89e3\u51b3\u201cTask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88\u201d\u9519\u8bef\uff1f \u5c0f\u4f19\u4f34\u4eec\u6709\u6ca1\u6709\u89c9\u5f97\u5b66\u4e60\u6587\u7ae0\u5f88\u6709\u610f\u601d\uff1f\u6709\u610f\u601d\u5c31\u5bf9\u4e86\uff01\u4eca\u5929\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765\u300a## Android Fragment \u5207\u6362\u5bfc\u81f4\u5b9a\u65f6\u5668\u95ea\u9000\uff1f\u5982\u4f55\u89e3\u51b3\u201cTask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88\u201d\u9519\u8bef\uff1f\u300b\uff0c\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u5728\u5b66\u4e60\u4e2d\u5bf9\u5176\u4e2d\u90e8\u5206\u77e5\u8bc6\u70b9\u6709\u7591\u95ee\uff0c\u6216\u8bb8\u770b\u4e86\u672c\u6587\u5c31\u80fd\u5e2e\u5230\u4f60\uff01 android fragment \u5207\u6362\u5bfc\u81f4\u5b9a\u65f6\u5668\u95ea\u9000\uff1atask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88 \u5728 android \u5e94\u7528\u4e2d\uff0cfragment \u662f\u7528\u6765\u7ba1\u7406 ui \u7ec4\u4ef6\u7684\uff0c\u5728 fragment \u751f\u547d\u5468\u671f\u4e2d\uff0c\u6839\u636e fragment \u7684\u53ef\u89c1\u6027\u4f1a\u89e6\u53d1\u4e0d\u540c\u7684\u56de\u8c03\u65b9\u6cd5\uff0c\u5982 onstart() \u548c onstop()\u3002 \u5728\u4f7f\u7528\u5b9a\u65f6\u5668\u65f6\uff0c\u901a\u5e38\u5728 onstart() \u4e2d\u5b89\u6392\u5b9a\u65f6\u5668\u4efb\u52a1\uff0c\u5728 onstop() \u4e2d\u53d6\u6d88\u5b9a\u65f6\u5668\u4efb\u52a1\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4ece\u53e6\u4e00\u4e2a fragment \u8fd4\u56de\u6b64 fragment \u540e\uff0c\u5e94\u7528\u53ef\u80fd\u4f1a\u95ea\u9000\uff0c\u5e76\u663e\u793a\u9519\u8bef\u6d88\u606f\u201ctask \u5df2\u5b89\u6392\u6216\u5df2\u53d6\u6d88\u201d\u3002 \u6b64\u9519\u8bef\u7684\u539f\u56e0\u662f\uff0ctimertask \u53ea\u80fd\u7531 timer \u8c03\u5ea6\u4e00\u6b21\u3002\u5728 onstart() \u4e2d\u91cd\u65b0\u521b\u5efa\u4e00\u4e2a timer \u4e0d\u4f1a\u89e3\u51b3\u95ee\u9898\uff0c\u56e0\u4e3a\u4f60\u5b9e\u9645\u4e0a\u9700\u8981\u91cd\u65b0\u521b\u5efa task\u3002 \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a \u5728 onstart() \u4e2d\uff0c\u4e0d\u8981\u91cd\u65b0\u521b\u5efa timer\u3002\u76f8\u53cd\uff0c\u521b\u5efa\u5e76\u5b89\u6392\u4e00\u4e2a\u65b0 task\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a @Override public void [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-47772","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=47772"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47772\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}