Reputation: 1070
Alarm is working fine when I am working with the emulator. But not working when i try on actual devices.
Output when app is open.
RTC #8: Alarm{2c1fc9e type 1 when 1486492260454 user.com.hlthee}
tag=*alarm*:user.com.hlthee/.UpdateTables
type=1 whenElapsed=+22h43m2s644ms when=2017-02-08 00:01:00
window=-1 repeatInterval=86400000 count=0
operation=PendingIntent{7c4e37f: PendingIntentRecord{3f5fbf4c user.com.hlthee broadcastIntent}}
But when I closed the app then this entry removed.Why?? That's why Alarm is not ringing.
Alarm receiver broadcaster manifest file.
<receiver android:name=".UpdateTables"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Please don't say use service and register the receiver there. I think I am registering the receiver in manifest it will works. And also alarm in working fine in emulator. Not able to solve this issue from last 3 days. Any helps will be helpfull.
I have tried these method also:
Anyone also facing the same problem.
Upvotes: 4
Views: 3008
Reputation: 159
Your problem is not properly explained, if your are setting an alarm manager with that intent and your app is forced stopped set : FLAG_INCLUDE_STOPPED_PACKAGES as flag in your intent...
If set, this intent will always match any components in packages that are currently stopped. This is the default behavior when FLAG_EXCLUDE_STOPPED_PACKAGES is not set. If both of these flags are set, this one wins (it allows overriding of exclude for places where the framework may automatically set the exclude flag).
If your problem is you're not receiving the BOOT_COMPLETED this is what i suggest:
First: in your project properties, under the Manifest Tab, there is a checkbox list for choosing the permissions you want to provide, one of which is RECEIVE_BOOT_COMPLETED. Check that to provide these permissions.
Second: if your app installed on external storage(SD card), you will never receive Boot Complete action. So you have to specify android:installLocation="internalOnly" in the manifest tag.
Third : since version Android 3.1+ you don't receive BOOT_COMPLETE if user never started your app at least once or user "force closed" application. This was done to prevent malware automatically register service. This security hole was closed in newer versions of Android.
Fourth : open an adb shell on your device and force the event like this to test :
am broadcast -a android.intent.action.BOOT_COMPLETED
Upvotes: 2
Reputation: 97
Do implement onTaskRemoved and onDestroy
@Override
public void onTaskRemoved(Intent rootIntent) {
//Set what to do when task is removed
super.onTaskRemoved(rootIntent);
}
@Override
public void onDestroy() {
//What to do when service i destroyed
super.onDestroy();
}
Upvotes: 0
Reputation: 2780
If you are working on the MI device then you have to do some settings. Go to Security/Permission/AutoStart/ Then select your app and enable it. Hope it will work.
Upvotes: 4