[英]WakefulBrodcastReceiver / Alert does not ring (Wakelock? Process killed?)
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).
如果我将警报时间设置为大约5分钟到30分钟,它将按预期方式响起,但是如果我将其设置为大约4个小时,则无论何时从不触摸我的设备(整夜)或使用设备,都不会响起定期(一天)。
In the main method I've got this Wackelock
: 在主要方法中,我有这个
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: 然后我这样调用我的
AlarmReceiver
:
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: 最后,我的
AlarmReceiver
看起来像这样:
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);
所以最
main.Alert(context);
问题是:为什么是main.Alert(context);
not called after a longer time? 长时间不打来? Is the process maybe killed by the
Android OS
? 这个过程可能被
Android OS
杀死了吗?
@Pixel_95 What's doing main.Alert(context);
@ Pixel_95在做什么
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);
无论如何,PowerManager在构造函数中需要为FULL_WAKE_LOCK(不是PARTIAL),或类似的东西,但是当您使用WakefullBroadcastReceiver时,您将需要调用
completeWakefulIntent(intent);
;。 to be able to wake device, and if you do that, you won't need the PowerManager code lines. 能够唤醒设备,如果您这样做,则不需要PowerManager代码行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.