Android Service自啟動注意事項分析
本文實例分析了Android Service自啟動注意事項。分享給大家供大家參考,具體如下:
@Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); if(intent == null) return; } @Override public void onDestroy() { super.onDestroy(); Intent intent = new Intent(SensorService.this, SensorService.class); startService(intent); } @Override public int onStartCommand(Intent intent, int flags, int startId) { // flags = Service.START_STICKY; flags = Service.START_REDELIVER_INTENT; return super.onStartCommand(intent, flags, startId); }
PS:重點就在這個 flags ,開始時用Service.START_STICKY; Service 經(jīng)常會自動FC查了好久才發(fā)現(xiàn)再次自啟動時候onStart里intent為null,改為flags = Service.START_REDELIVER_INTENT;就可以了。
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android調(diào)試技巧與常見問題解決方法匯總》、《Android開發(fā)入門與進階教程》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
相關(guān)文章
Android 讀取assets和raw文件內(nèi)容實例代碼
這篇文章主要介紹了Android 讀取assets和raw文件內(nèi)容的相關(guān)資料,并附簡單實例代碼,需要的朋友可以參考下2016-10-10Flutter實現(xiàn)PopupMenu彈出式菜單按鈕詳解
這篇文章主要介紹了Flutter實現(xiàn)PopupMenu彈出式菜單按鈕,PopupMenuButton是一個用于創(chuàng)建彈出菜單的小部件,當用戶點擊觸發(fā)按鈕時,PopupMenuButton會在屏幕上方或下方彈出一個菜單,感興趣想要詳細了解可以參考下文2023-05-05Android組件ContextMenu實現(xiàn)長按事件
這篇文章主要為大家詳細介紹了Android組件ContextMenu實現(xiàn)長按事件,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-04-04android?studio?項目?:UI設(shè)計高精度實現(xiàn)簡單計算器
這篇文章主要介紹了android?studio?項目?:UI設(shè)計高精度實現(xiàn)簡單計算器,自主完成一個簡單APP的設(shè)計工作,綜合應(yīng)用已經(jīng)學(xué)到的Android?UI設(shè)計技巧,下面來看看實驗實現(xiàn)過程2021-12-12Android AsyncTask的缺陷和問題總結(jié)
這篇文章主要介紹了Android AsyncTask的缺陷和問題總結(jié)的相關(guān)資料,需要的朋友可以參考下2017-03-03