在Android 4.4系统,刷卡应用程序在最近的任务永久杀死应用程序的服务。知道为什么吗? [英] In android 4.4, swiping app out of recent tasks permanently kills application with its service . Any idea why?

查看:159
本文介绍了在Android 4.4系统,刷卡应用程序在最近的任务永久杀死应用程序的服务。知道为什么吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不像previous版本,在4.4,刷卡应用程序在最近的任务永远伴随着它的服务(如强制停止)杀死的应用程序,即使它在后台运行的服务。它显示了0流程1服务,但服务还不能正常工作。理想情况下它不应该终止后台服务,并且它没有在之前的4.3版本。任何想法,为什么会发生在4.4?

Unlike previous versions, in 4.4, swiping app out of recent tasks permanently kills app along with its service(like force-stop) even though it's running background services. It shows 0 processes 1 service but service also doesn't work. Ideally it shouldn't kill background service, and it doesn't in versions prior to 4.3. Any idea why is it happening in 4.4?

推荐答案

明白了。它在4.4的错误。我想这和它的工作完美的罚款(它是一个肮脏的锻炼,虽然)。

Got it. Its a bug in 4.4. I tried this and it worked perfectly fine(its a dirty workout though).

只需重写此方法 - :

Just override this method -:

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);
}

这篇关于在Android 4.4系统,刷卡应用程序在最近的任务永久杀死应用程序的服务。知道为什么吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆