简体   繁体   English

当我杀死我的应用程序时,BroadcastReceiver无法正常工作

[英]BroadcastReceiver not working when I kill my application

I have noticed than whenever I manually kill my application by longpressing the back button of my cellphone my broadcast receiver stops working. 我注意到,每当我通过长按手机的后退按钮手动杀死我的应用程序时,我的广播接收器就会停止工作。 The receiver is in charge of displaying a notification every time the user hangs up a phone call and the same is registered in the manifest.xml. 每次用户挂断电话时,接收方负责显示通知,并在manifest.xml中注册该通知。

Is this the normal/expected behaviour? 这是正常/预期的行为吗? I thought the receiver should continue to work even if the user decides to kill my application... Is there a way to prevent this? 我认为接收器应该继续工作,即使用户决定杀死我的应用程序......有没有办法防止这种情况?

Thanks. 谢谢。

Edit 编辑

Here's the manifest entry for the receiver: 这是接收器的清单条目:

<receiver android:name=".BroadcastReceivers.CallReceiver" android:enabled="true">
   <intent-filter>
       <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
       <action android:name="android.intent.action.PHONE_STATE" />
   </intent-filter>
</receiver>

There are ~7 billion people on the planet. 这个星球上有大约70亿人。 Only you know what you mean by "kill". 只有你知道“杀戮”是什么意思。

The symptoms that you are describing, though, are consistent with a "force stop". 但是,您所描述的症状与“强制停止”一致。 A user normally force-stops an application by going to Settings, finding your app in the list of installed apps, and tapping on the "Force Stop" button for your app. 用户通常会通过转到“设置”,在已安装的应用列表中找到您的应用,以及点击应用的“强制停止”按钮来强制停止应用。 There are some devices and firmware builds that make "Force Stop" more readily accessible than this -- such devices and firmware builds were written by drooling idiots IMHO. 有一些设备和固件构建使“强制停止”比这更容易访问 - 这样的设备和固件版本是由流口水的白痴恕我直言写的。

If your app is force-stopped, your code will never run again, until something uses an explicit Intent to start one of your components. 如果您的应用程序被强制停止,则代码将永远不会再次运行,直到某些内容使用显式Intent启动您的某个组件。 Usually, the user does this by tapping on your app's icon in the home screen's launcher. 通常,用户通过点击主屏幕启动器中的应用程序图标来执行此操作。 Until the user does this, your BroadcastReceiver will not work, and there is nothing you can do about it. 在用户执行此操作之前,您的BroadcastReceiver将无法工作,并且您无法对其进行任何操作。

Rather than using some on-device feature to "kill" your app, try terminating its process via DDMS. 而不是使用一些设备上的功能来“杀死”您的应用程序,尝试通过DDMS终止其进程。 If your app continues to work in that case, then however you elected to "kill" your app before is doing a "force-stop". 如果您的应用程序继续在这种情况下工作,那么您选择在执行“强制停止”之前“杀死”您的应用程序。 Merely having your process be terminated, such as due to low memory conditions, should not prevent you from receiving future broadcasts. 仅仅因为内存不足而终止您的进程不应该阻止您接收未来的广播。

I know that some devices (like my ASUS) are deleting static receivers when you stop an application, yours is probably one of those. 我知道有些设备(比如我的ASUS)在你停止应用程序时会删除静态接收器,你的可能就是其中之一。 The only thing you can do is trying with emulator or other device. 您唯一能做的就是尝试使用模拟器或其他设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 杀死应用程序后我的工作经理不工作 - My work manager is not working after kill the application 应用程序未运行时的BroadcastReceiver - BroadcastReceiver when application is not running 用户退出应用程序时,Android AlarmManager BroadcastReceiver无法正常工作 - Android AlarmManager BroadcastReceiver not working when user exits the application 从最近的任务中删除应用程序时,Android静态BroadcastReceiver无法正常工作 - Android Static BroadcastReceiver not working when Application is removed from Recent Tasks 当我的应用程序在后台运行时,如何让 android 系统杀死我的应用程序? - How can I let android system kill my application when it runs in backgroud? 应用程序只有“广播接收器”无法正常工作 - Application have Only BroadcastReceiver is not working BroadcastReceiver无法在我的Android应用程序中运行 - BroadcastReceiver is not working in my android app Xamarin Android:我的 [BroadcastReceiver] 不工作 - Xamarin Android: My [BroadcastReceiver] is not working 内存终止或销毁活动时,Service和BroadcastReceiver在MI电话中不起作用 - Service and BroadcastReceiver not working in MI phone at time of Memory kill or Destroy Activity 当我关闭其他活动时,为什么我的广播接收器不起作用? - Why my broadcastreceiver doesnt work when i close other Activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM