Android ACTION_SHUTDOWN intent not working when my app is closed. It works well when app is in foreground or background. How can achieve the same performance when app is closed?
Asked
Active
Viewed 9,596 times
1
-
Have you used background service? i mean when your app is not in background or closed maintain broadcast reciever within your service so this should help you – Kishan Soni Dec 05 '15 at 07:01
2 Answers
2
Check the following in your manifest file
<uses-permission android:name="android.permission.DEVICE_POWER" />
.....
<receiver android:name=".ShutdownReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
check here: Android ACTION_SHUTDOWN Broadcast not working
-
Yes I have added the above lines. But still the BroadcastReceiver is not called when I switch off the device while the app is closed but the BroadcastReceiver is called when the app is in background and I switch off the device – Aditya Borde Dec 05 '15 at 07:01
-
make sure you're not registering for system level things with LocalBroadcastManager.registerReceiver(), it should be context.registerReceiver() – Saik Caskey Feb 08 '17 at 15:49
0
According to official doc.
Broadcast Action: Device is shutting down. This is broadcast when the device is being shut down (completely turned off, not sleeping). Once the broadcast is complete, the final shutdown will proceed and all unsaved data lost. Apps will not normally need to handle this, since the foreground activity will be paused as well.
This is a protected intent that can only be sent by the system.
May include the following extras:
EXTRA_SHUTDOWN_USERSPACE_ONLY
a boolean that is set to true if this shutdown is only for userspace processes. If not set, assumed to be false.
Constant Value: "android.intent.action.ACTION_SHUTDOWN"

vishal jangid
- 2,967
- 16
- 22