BroadcastReceiver doesn't work after scrolling the app from the list of recents
I am working on an application for internet calling. In my application I use BroadcastReceiver
to call the call screen when the application receives an FCM data message with specific keys. Usually works fine, but if I remove my app from the recent apps list it doesn't work. It looks like mine BroadcastReceiver
stops working after it starts the application because all FCM services are still there and it also receives FCM messages and shows in logcat too.
I am registering my broadcast receiver in Java code ( not in the manifest).
I used the service class to register the broadcast receiver and also overridden onTaskRemoved()
and used AlarmManager
to continue, but it didn't work either.
Why BroadcastReceiver
won't it be launched and how to solve the problem?
source to share
I am registering my broadcast receiver in Java code (not in the manifest).
This is the cause of your problem. When a user selects your application from the address list, your application process is killed. Thus, yours is BroadcastReceiver
also destroyed.
Register your BroadcastReceiver
in AndroidManifest
, then it onReceive()
will be called regardless of whether your application has a current process or not.
source to share