[英]custom static broadcastreceiver not working when app is removed from recent apps
when my app is removed from recent apps, my custom broadcastreceiver is not working, onreceive can't be excuted any more, but we know system broadcast can be received when app is removed from recent apps.is the phenomenon right? 当我的应用程序从最近的应用程序中删除时,我的自定义广播接收器不起作用,无法再接收onreceive,但是我们知道从最近的应用程序中删除应用程序后可以接收系统广播。这种现象对吗? or is my custom broadcastreceiver not true?
还是我的自定义广播接收器不正确? thanks for help.
感谢帮助。
<receiver android:name=".AlarmBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="action_alarm_trigger_sync" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Intent serviceIntent = new Intent();
serviceIntent.setAction(AlarmBroadcastReceiver.ACTION);
serviceIntent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
PendingIntent servicePendingIntent =
PendingIntent.getBroadcast(context,
AlarmBroadcastReceiver.SERVICE_ID, serviceIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(
AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(),
interval,
servicePendingIntent
);
BroadcastReceiver
code (pasted from a comment): BroadcastReceiver
代码(从注释粘贴):
@Override
public void onReceive(Context context, Intent intent) {
Log.i("AlarmManager","AlarmBroadcastReceiver start");
try {
FileUtils.writeFileSdcardFile("hhaa"+ System.currentTimeMillis()+"\n");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void writeFileSdcardFile(String write_str) throws IOException {
File mFile = new File("/mnt/sdcard/alram_record2.text");
if(!mFile.exists()){
mFile.createNewFile();
}
FileOutputStream fout = new FileOutputStream(mFile, true);
byte [] bytes = write_str.getBytes();
fout.write(bytes);
fout.close();
}
Try this code: 试试这个代码:
<receiver android:name=".AlarmBroadcastReceiver" />
and: 和:
Intent serviceIntent = new Intent(this, AlarmBroadcastReceiver.class);
PendingIntent.getBroadcast(context, AlarmBroadcastReceiver.SERVICE_ID, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), interval, servicePendingIntent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.