В отличие от предыдущих версий, в 4.4, прокручивание приложения из последних задач постоянно убивает приложение вместе со своим сервисом (например, принудительный останов), хотя он работает с фоновыми службами. Он показывает 0 процессов 1, но сервис также не работает. В идеале он не должен убивать фоновое обслуживание, и он не находится в версиях до 4.3. Любая идея, почему это происходит в 4.4?
В android 4.4, прокручивание приложения из последних задач постоянно убивает приложение своим сервисом. Любая идея почему?
Ответ 1
Получил это. Его ошибка в 4.4. Я пробовал это, и он работал отлично (его грязная тренировка, хотя).
Просто переопределите этот метод -:
public void onTaskRemoved(Intent rootIntent) {
Log.e("FLAGX : ", ServiceInfo.FLAG_STOP_WITH_TASK + "");
Intent restartServiceIntent = new Intent(getApplicationContext(),
this.getClass());
restartServiceIntent.setPackage(getPackageName());
PendingIntent restartServicePendingIntent = PendingIntent.getService(
getApplicationContext(), 1, restartServiceIntent,
PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmService = (AlarmManager) getApplicationContext()
.getSystemService(Context.ALARM_SERVICE);
alarmService.set(AlarmManager.ELAPSED_REALTIME,
SystemClock.elapsedRealtime() + 1000,
restartServicePendingIntent);
super.onTaskRemoved(rootIntent);
}
Ответ 2
Из этой проблемы Служба переднего плана, убитая при получении трансляции после того, как acitivty отменил список задач
Вот решение
На переднем плане:
@Override
public void onTaskRemoved( Intent rootIntent ) {
Intent intent = new Intent( this, DummyActivity.class );
intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
startActivity( intent );
}
В манифесте:
<activity
android:name=".DummyActivity"
android:theme="@android:style/Theme.NoDisplay"
android:enabled="true"
android:allowTaskReparenting="true"
android:noHistory="true"
android:excludeFromRecents="true"
android:alwaysRetainTaskState="false"
android:stateNotNeeded="true"
android:clearTaskOnLaunch="true"
android:finishOnTaskLaunch="true"
/>
В DummyActivity.java:
public class DummyActivity extends Activity {
@Override
public void onCreate( Bundle icicle ) {
super.onCreate( icicle );
finish();
}
}