I've an app which should be an Alarm clock. If I set the Alert time about 5min oder 30min, it will ring as it should, but if I put it something like 4 hours away, it won't ring, neither if my device is never touched (over night) nor if I use it regularly (at day).
In the main method I've got this Wackelock
:
PowerManager powman = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powman.newWakeLock(PowerManager.FULL_WAKE_LOCK,"MyWakelockTag");
wakeLock.acquire();
Then I call my AlarmReceiver
like this:
Intent alarmIntent = new Intent(main.this, AlarmReceiver.class);
PendingIntent alarmPendingIntent = PendingIntent.getBroadcast(main.this, 8932, alarmIntent, 0);
AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
manager.set(AlarmManager.RTC_WAKEUP, AlertDate.getTime(), alarmPendingIntent);
And finally my AlarmReceiver
looks like this:
public class AlarmReceiver extends WakefulBroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
main.Alert(context);
}
}
My Manifest is here:
<uses-permission android:name="android.permission.WAKE_LOCK" />
...
<application
...
<receiver
android:name=".AlarmReceiver"
android:permission="android.permission.WAKE_LOCK">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
So the very shorts question is: why is main.Alert(context);
not called after a longer time? Is the process maybe killed by the Android OS
?
@Pixel_95 What's doing main.Alert(context);
? Anyway, PowerManager will need to be FULL_WAKE_LOCK in constructor(not PARTIAL), or something like that, but when you use WakefullBroadcastReceiver, you will need to call completeWakefulIntent(intent);
to be able to wake device, and if you do that, you won't need the PowerManager code lines.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.