[英]BroadcastReceiver stops receiving after few days (Local Notification)
I'm using a BroadCastReceiver for triggering alarm which is working fine for like 2-3 days, after that it stops working, I am not receiving any alerts in my BroadcastReceiver. 我正在使用BroadCastReceiver来触发警报,该警报在2-3天内正常工作,在该警报停止工作之后,我的BroadcastReceiver中没有收到任何警报。 Is there a lifeSpan for Pending Intent?
有待定意图的寿命吗? Actually I'm creating alarms for 30 days.
实际上,我正在创建30天的警报。 I'm using PendingIntents.
我正在使用PendingIntents。 Here is the code for PendingIntent:
这是PendingIntent的代码:
PendingIntent pendingIntentScheduler = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntentScheduler);
and the receiver at BroadcastReceiver: 和BroadcastReceiver的接收器:
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
Log.d("onReceive", "this is broadcast reciever");
}
Android Manifest Permission: Android清单权限:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<application>
<receiver android:name=".medicine.modal.AlarmReceiver" android:permission="android.permission.WAKE_LOCK"
android:enabled="true" android:exported="true" android:process=":remote">
<intent-filter>
<action android:name="com.healthsaverz.nimap.healthmobile.healthsaverz.mainscreen.controller.NotificationActivity" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
I found a solution, not legitimate but a bypass. 我找到了解决方案,不是合法的,而是绕过的。 May be this will help someone.
也许这会帮助某人。 What I did is put a repeating Alarm which repeats at every 24 hours, in which I'm recreating all the Pending Intents.
我所做的是放置一个重复警报,该警报每24小时重复一次,其中我将重新创建所有待处理的意图。 Since the life of pending intent is 2-3 days (According to what i found in my app).
由于待定意图的寿命为2-3天(根据我在应用程序中发现的信息)。 This results in creating new Pending Intents everyday.
这导致每天创建新的待定意向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.