CountDownTimer not working in IntentService

I use wakefullintentservice . While it worked perfectly, I used this library in many projects.

but I know that in my application I use the CountDownTimer Class.I don’t know why it is not working. I am trying to debug, it does not run the CountDownTimer code. After calling countDownTimer.start (); nothing happened, just released a blocked call.

Any help should be fixed. Thanks in advance.

I just want to do some work in IntentService with 1 Sec Delay.mean, if it can be without using CountDownTimer, please tell me.

Here is my code

public class AppService extends WakefulIntentService {
Context ctx;
private CountDownTimer countDownTimer;
List<GCMessagingUtils> gcmessagelist;
public static final String Tag="AppService.java";
private long startTime;
int index = 0;
private final long interval = 1 * 1000;

public AppService() {
    super("AppService");
}

@Override
protected void doWakefulWork(Intent intent) {
    Log.e(Tag, "doWakefulWork");
    OnAlarmReceiver.isSendingDataOn = true;
    ctx = getApplicationContext();
    DatabaseHandler db = new DatabaseHandler(ctx);
    gcmessagelist = db.getAllGCMessages();
    startTime = gcmessagelist.size() * 1000;
    countDownTimer = new MyCountDownTimer(startTime, interval);
    countDownTimer.start();

}

public class MyCountDownTimer extends CountDownTimer {
    public MyCountDownTimer(long startTime, long interval) {
        super(startTime, interval);
    }

    @Override
    public void onFinish() {
        OnAlarmReceiver.isSendingDataOn = false;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        Log.e(Tag,"Inside OnTick");
        if (index < gcmessagelist.size()) {
            GCMessagingUtils gcmessage = gcmessagelist.get(index);
            //Do Some Work
            index++;
        }
    }
}

}

Problem resolved:

With pskink solution

Hope this helps someone.

I Just Place Looper.loop() doWakefulWork. , .

*
*
countDownTimer = new MyCountDownTimer(startTime, interval);
countDownTimer.start();
Looper.loop() 
}

CountDownTimer Looper

 @Override
public void onFinish() {
       OnAlarmReceiver.isSendingDataOn = false;
       Looper.myLooper().quit();
}
+4
1

, , IntentService. , IntentService, , , , .

, doWakefulWork , IntentService . CountDownTimer IntentService.

+1

All Articles