本文介绍了我的警报管理器无法在后台运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为应用程序警报管理器做了准备.我需要每小时运行一次,并检查数据是否已更改.

I prepared for my application alarm manager. I need run this every hour and check if data is changed.

我已将警报管理器设置如下:

 Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR, 1);
    android.app.AlarmManager alarmMgr = (android.app.AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(mContext, AnalysisNotificationReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, ALARM_ID, intent, 0);
    if (Calendar.getInstance().after(cal)) {
        cal.add(Calendar.DAY_OF_MONTH, 1);
    }
    alarmMgr.setRepeating(android.app.AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 60 * 60 * 1000, pendingIntent);

它应该每60分钟工作一次,我不确定我是否设置正确,但是在应用关闭时不起作用.

It's should work in every 60 minutes I'm not sure if I set correctly but doesn't work when app close.

有人知道吗?谢谢

推荐答案

您可以尝试一下,它对我有用

You can try this, it worked for me

AlarmManager alarmManager= (AlarmManager) getSystemService(Context.ALARM_SERVICE);

Intent scheduleServiceExecuterIntent = new Intent(this, ScheduledServiceExecuter.class);

scheduleServiceExecuterIntent.putExtra("state", "Main");
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, request_code, intent, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, AlarmManager.INTERVAL_HOUR, pendingIntent);

这篇关于我的警报管理器无法在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-27 21:59