android防被殺

來源:互聯網
上載者:User

標籤:des   android   style   blog   http   io   color   ar   for   

android防被殺

現在的清理軟體如360都有一鍵清理的功能,他會後台啟動並執行程式一個個kill掉。程式死掉後也不會走正常的生命週期,比如調用ondestory方法。怎麼才能讓程式一直運行在後台,不被360殺掉呢?

在測試了幾種方法後,終於找到一種方法。android有個同步工具Sync Adapter,你註冊了之後可以周期運行。這樣,即使你的進程被他殺掉後,也會在一定時間內自動重啟。 android develop網站有他的介紹 Run the Sync Adapter Periodically

大家可以下載官方的樣本看下他是怎麼聲明註冊的 其中addPeriodicSync方法就是添加周期啟動並執行方法 

1 android.content.ContentResolver.addPeriodicSync(Account account, String authority, Bundle extras, long pollFrequency)

pollFrequency就是周期的時間,是以秒為單位的。

不過在實際的測試過程當中,發現他周期不一定就是你寫的時間,有時快有時慢,這是因為

 Although these sync are scheduled at the specified frequency, it may take longer for it to actually be started if other syncs are ahead of it in the sync operation queue. This means that the actual start time may drift.

你的同步器會受到別人的同步器的影響。

android防被殺

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.