广播接收器不接收应用程序后被杀 [英] Broadcast Receiver doesn't receive after app killed

查看:131
本文介绍了广播接收器不接收应用程序后被杀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个广播接收器来管理这些事件(ACTION_SCREEN_ON,ACTION_SCREEN_OFF和ACTION_USER_ preSENT)。注册我的广播接收器像这样在我的主要活动

I have created a broadcast receiver to manage these events (ACTION_SCREEN_ON, ACTION_SCREEN_OFF and ACTION_USER_PRESENT). I register my broadcast receiver like this in my main activity

IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);

mReceiver = new UnlockReceiver();


registerReceiver(mReceiver, filter);

我的问题是我的应用程序被杀害后UnlockReceiver没有收到(当我从应用程序选择了Swype它)。我有这个问题,因为这些广播不能宣布舱单我试着解决它使用服务和AlarmManager。我该如何解决呢?

My problem is that the UnlockReceiver doesn't receive after my app is killed (when I swype it from app selector). I have this problem because these broadcast can't be declared on Manifest I've tried solve it using Service and AlarmManager. How can I solve it?

推荐答案

在Android 3.1开始,系统的软件包管理器保持的是处于停止状态的应用程序的轨道,并且提供从后台进程和其他应用控制他们推出的一种手段

Starting from Android 3.1, the system's package manager keeps track of applications that are in a stopped state and provides a means of controlling their launch from background processes and other applications.

请注意,一个应用程序的停止状态是不一样的作为活动的停止状态。该系统独立管理这两个停止状态。

Note that an application's stopped state is not the same as an Activity's stopped state. The system manages those two stopped states separately.

该平台定义了两种新的意图的标志,让发件人指定意向是否应该被允许在停止的应用程序来激活组件。

The platform defines two new intent flags that let a sender specify whether the Intent should be allowed to activate components in stopped application.

FLAG_INCLUDE_STOPPED_PACKAGES - 包括在解决对潜在目标名单停止应用程序的意图过滤器。
FLAG_EXCLUDE_STOPPED_PACKAGES - 排除从潜在目标名单停止应用程序的意图过滤器。
当这些标志没有或两者的意图被定义,则默认行为是包括潜在目标名单停止应用程序的过滤器。

FLAG_INCLUDE_STOPPED_PACKAGES — Include intent filters of stopped applications in the list of potential targets to resolve against. FLAG_EXCLUDE_STOPPED_PACKAGES — Exclude intent filters of stopped applications from the list of potential targets. When neither or both of these flags is defined in an intent, the default behavior is to include filters of stopped applications in the list of potential targets.

http://developer.android.com/国际/​​ ZH-CN /约/版本/ Android的3.1.html

这篇关于广播接收器不接收应用程序后被杀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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