亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

START_STICKY無法在Android KitKat上運行

START_STICKY無法在Android KitKat上運行

海綿寶寶撒 2019-08-31 11:23:17
我的一個應用程序有一個backgrouod服務,它使用START_STICKY返回代碼onStartCommand在系統殺死它時自動重啟。似乎這不再適用于Android KitKat。這有什么解決方案嗎?我應該在Kitkat做一些不同的事情來保持服務的運行嗎?注意:在Android-Devlopers小組中有一個關于從最近的應用列表行為中滑動應用程序的類似討論。這兩個問題可以相關嗎? https://groups.google.com/forum/#!topic/android-developers/H-DSQ4-tiac編輯:看到Android問題跟蹤器上有開放的錯誤:https://code.google.com/p/android/issues/detail?id=63793 https://code.google.com/p/android/issues/detail?id=63618Edit2:即使服務正在運行startForeground,在單獨的進程android:stopWithTask="false"中使用AndroidManifest.xml文件中的標志,也會發生同樣的情況......Edit3:Android問題跟蹤器上的更多相關錯誤:https://code.google.com/p/android/issues/detail?id=62091 https://code.google.com/p/android/issues/detail?id=53313 https://code.google。 COM / p /安卓/問題/細節?ID = 104308是否有某種解決方法來獲得以前的行為?
查看完整描述

3 回答

?
斯蒂芬大帝

TA貢獻1827條經驗 獲得超8個贊

似乎這是Android 4.4中存在的一個錯誤,并通過以下方式解決了這個問題:


@Override

public void onTaskRemoved(Intent rootIntent) {

    Intent restartService = new Intent(getApplicationContext(),

            this.getClass());

    restartService.setPackage(getPackageName());

    PendingIntent restartServicePI = PendingIntent.getService(

            getApplicationContext(), 1, restartService,

            PendingIntent.FLAG_ONE_SHOT);

    AlarmManager alarmService = (AlarmManager)getApplicationContext().getSystemService(Context.ALARM_SERVICE);

    alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() +1000, restartServicePI);


}


查看完整回答
反對 回復 2019-08-31
  • 3 回答
  • 0 關注
  • 706 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號