Android service + countdown = not working

Well, that pissed me off. Is there a limit on countdown services?

I tried so many methods so that the countdown timer works in the service, but it always fails. It just never gets to the finish () part!

So is there a limit on services and countdowns? Please help me...

Here is the service:

public class ss extends IntentService { public ss() { super("ss"); } @Override protected void onHandleIntent(Intent intent) { new CountdownTimer(30000, 1000) { public void onTick(long millisUntilFinished) { } public void onFinish() { executemymethod(); //it never gets here! } }.start(); } } 

As you can see, the code is simple and correct, but still executemymethod (); never executed! No errors ... Please give me a solution!

+4
source share
1 answer

If you want to do such things, you should use a regular service, not an IntentService. Here's what the docs about IntentService say :

Clients send requests through startService (Intent) calls; the service starts as needed, processes each intention in turn using the workflow, and stops when work ends.

Since the countdown is asynchronous, operation ends when the countdown timer starts. Then the IntentService shuts down and probably disables the thread.

+4
source

Source: https://habr.com/ru/post/1382743/


All Articles