Why is my service blocking the user interface?

I created a service (service B) from Activity (Activity A). And from service B, I created another service (service C). C service was previously a thread, not a service. Since he ended up having problems, I changed it to a service. Service C starts a while loop with 3 second calls to Thread.sleep. But the general condition is this does not stop. The log shows that the service is running. But the user interface is locked, and after a few minutes the system will ask me whether to disable it.

How to make this service unlocked?

+5
source share
4 answers

From service documentation in Android

. , ; , , , .

. , ( , ).

- , .

+3

, C , ( )

+2

, , . , , , :

  • ,
  • , , , , , .
  • onCreate . onStartCommand, , . Ex. , . , .

    , onCreate , , , , . .

+2
source

Services always start in the main thread. You need to create a background thread or restart it TimerTask, etc. In C service, to avoid blocking the user interface thread.

0
source

All Articles