Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Alarm Manager服务不工作_Android_Alarmmanager - Fatal编程技术网

Android Alarm Manager服务不工作

Android Alarm Manager服务不工作,android,alarmmanager,Android,Alarmmanager,我在这里找到了很多关于报警管理器的解决方案,但似乎都不起作用 我使用以下方法创建后台服务: public void scheduleSync() { Intent intent = new Intent(this, SyncReceiver.class); final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT

我在这里找到了很多关于报警管理器的解决方案,但似乎都不起作用

我使用以下方法创建后台服务:

public void scheduleSync() {
    Intent intent = new Intent(this, SyncReceiver.class);
    final PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), SYNC_INTERVAL, pendingIntent);
    Log.d(TAG, "Sync scheduled.");
}
SyncReceiver类是:

public class SyncReceiver extends BroadcastReceiver {
    private static final String TAG = "SyncReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Intent i = new Intent(context, WebBackendSyncService_.class);
        context.startService(i);
        Log.d(TAG, "WebBackendSyncService started.");
    }
}
这就是用Android注释定义的WebBackendSyncService:

@EIntentService
public class WebBackendSyncService extends IntentService {
    public static final String ACTION = "com.invoicing.networking.WebBackendSyncService";
    private static final String TAG = "WebBackendSyncService";

    @RestService
    APIService restClient;

    public WebBackendSyncService() { super(ACTION);}


    @Override
    protected void onHandleIntent(Intent intent) {
        Log.d(TAG, "Handling sync intent.");
        sendInvoices();
    }

    @Background
    void sendInvoices() {
         SyncData.sendInvoices(restClient);
    }
}
舱单中的服务和广播接收器:

<service
     android:name=".networking.WebBackendSyncService_"
     android:exported="false" />

 <receiver
     android:name=".networking.SyncReceiver"
     android:process=":remote" />
在过去的几个小时里,看着那些电话线,我不得不在这里寻求帮助。我希望你能看到我错过的东西

查看要同步的控制台输出计划。

首先,您的元素在android:name属性中有一个恶意下划线,需要删除该下划线

其次,摆脱android:process=:remote。为双线广播接收器分叉整个过程不是很有效,它会干扰下一个修复


第三,从BroadcastReceiver切换到WakefulBroadcastReceiver,并按照使用该类的说明操作,因为现在设备在服务工作之前或期间都会很容易进入睡眠状态。

在删除未使用的依赖项和多索引配置后得到解决。但是,代码本身没有任何更改,它的工作原因未知

我必须坚持使用下划线,因为它由于Android注释而无法编译。删除:remote并更改为WakefulBroadcastReceiver在这一点上没有帮助。@drive235:我必须坚持下划线,因为它由于Android注释而无法编译-哦,是的,抱歉,错过了这一部分。您可以使用adb shell dumpsys alarm确认您的报警已安排。此外,在警报应关闭时,使用堆栈跟踪监控LogCat是否存在警告/错误。你可能还想暂时调回targetSdkVersion 18并使用setRepeating,因为这种不精确性往往会妨碍调试。我暂时删除了所有Android注释内容,只是想看看它是否有作用——它没有。但是,您建议的命令显示唤醒时间间隔正确:*walarm*:com.invoicing/.networking。SyncReceiver@drive235:并且您没有从SyncReceiver本身获得任何信息,无论是以Log.d调用的形式还是某些堆栈跟踪的形式,表明SyncReceiver无法实例化还是其他什么?如果是这样的话,那就太奇怪了,我对发生的事情没有一个很好的答案,我什么也得不到。没有日志,没有堆栈跟踪。即使调试器也不会在onReceive中停止。这可能与注释有关。谢谢你的努力!