OnTaskRemoved is called after onCreate in the running service, scrolling from the list of recent applications

I have a service launched from Activity, the service is working fine onCreate , onStartCommand , called correctly. In the settings → the application works with its showing 1 process and 1 service .
Now that I have removed my application from the recent list of applications. The service is recreated. In the settings → the application is running, it shows 0 process and 1 service restarting... And onCreate , onStartCommand , onTaskRemoved .

Now the problem is one onTaskRemoved application, called right after you open the application, and then onCreate , and in another onTaskRemoved application, onTaskRemoved takes time and onCreate called after onCreate .

Why does this other behavior exist? Any suggestion will help me. Please provide your comments and comments.

 08-26 15:43:48.611: D/PassiveService(15359): PASS_IVE, onCreate... 08-26 15:43:48.611: I/PassiveService(15359): PASS_IVE, registerReceivers... 

After scrolling

 08-26 15:44:05.789: D/PassiveService(15499): PASS_IVE, onCreate... 08-26 15:44:05.809: I/PassiveService(15499): PASS_IVE, registerReceivers... 08-26 15:44:05.839: I/PassiveService(15499): PASS_IVE, onTaskRemoved... 
+3
android kill-process android-service
Aug 26 '15 at 10:32
source share
1 answer

A call to the onTaskRemoved of a running service (when the application is withdrawn from the latest applications) will usually be delayed if we carry out any heavy materials related to the user interface or send messages to recipients in the service .

For example, suppose you download a 50 MB file from a web server, so from a web server every time you read 1024 bytes of stream data as a buffer and the data that you write to a file on the device.

In the meantime, you are updating the progress in the user interface thread, which means that every KB that you upgrade to the user interface thread will cause the application to freeze.

So, between you, if you delete the last list of applications, the system will try to stop the service, but since the service is in contact with the user interface thread, the system will not be able to stop this service, but it will create a new service , although the old service has not been stopped yet.

Once the old service has finished communicating with the UI thread, onTaskRemoved () is called, and the old service will be stopped. The new service will run in the background.

+1
Jan 06 '17 at 13:26
source share



All Articles