C
C
Copperfield2015-06-08 16:00:09
Android
Copperfield, 2015-06-08 16:00:09

How to stopudova wake up the phone from deep sleep for the service?

The bottom line is this: once every 12 hours, the service should start, make some calculations and send them to the server.
The problem is this: a couple of times everything works fine, then it stalls. The logs show that a call does not come to my receiver, which processes the AlarmManager intent and starts the service.
It seems that he did everything according to the rules so that the phone wakes up. Below is the code. Who will tell you what the problem is?
Method that sets the AlarmManager:

public void startStatisticSender() {
        systemAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                System.currentTimeMillis() + STATISTIC_SENDER_INTERVAL,
                STATISTIC_SENDER_INTERVAL, createStatisticIntent(STATISTIC_SENDER, KEY_SEND_STATISTIC));
    }

    private PendingIntent createStatisticIntent(int id, String action) {
        Intent intent = new Intent(context, StatisticReceiver.class);
        intent.setAction(action);
        return PendingIntent.getBroadcast(context, id, intent, 0);
    }

Receiver:
public class StatisticReceiver extends WakefulBroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals(AlarmHelper.KEY_SEND_STATISTIC)) {
            handleSendStatistic(context);
        }
    }

    private void handleSendStatistic(Context context){
        Intent intent = new Intent(context, StatisticService.class);
        intent.setAction(StatisticService.KEY_SEND_STATISTIC);
        startWakefulService(context, intent);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bimeg, 2015-06-08
@bimeg

AlarmManager.setRepeating
Note: as of API 19, all repeating alarms are inexact. If your application needs precise delivery times then it must use one-time exact alarms, rescheduling each time as described above. Legacy applications whose targetSdkVersion is earlier than API 19 will continue to have all of their alarms, including repeating alarms, treated as exact.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question