简体   繁体   English

从最新应用程序中删除应用程序后,自定义静态广播接收器不起作用

[英]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.

相关问题 从最近的任务中删除应用程序时,Android静态BroadcastReceiver无法正常工作 - Android Static BroadcastReceiver not working when Application is removed from Recent Tasks 从最近的应用程序列表中删除应用程序时,BroadcastReceiver无法正常工作 - BroadcastReceiver Not Working When App is removed from recent app list 从最近的应用程序中删除应用程序后,IntentService停止工作 - IntentService stops working when app is removed from recent apps 从最近的应用程序中删除应用程序时,“前台”服务将被终止 - “foreground” service is killed when App is removed from recent apps Android,从“最近的应用”中删除应用时取消通知 - Android, cancel notification when app is removed from “Recent apps” 从最近的应用程序中删除后,请不要杀死应用程序 - Don't kill app when removed from recent apps 自定义静态BroadcastReceiver无法正常工作 - Custom static BroadcastReceiver not working 当我们从最近的应用程序中清除应用程序时,服务会停止工作吗? - Service will stop working when we clear the app from recent apps? 从最近的应用程序列表中删除应用程序时,将调用哪些生命周期事件? - Which lifecycle events are called when an app is removed from recent apps list? android中的GCM,当从“设备最近的应用”部分中删除该应用实例时,未显示预期的活动 - GCM in android, not showing the intended activity when the app instance is removed from the Devices RECENT Apps section
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM