Java – the way to invoke Android services in different threads. Is it still running on the main thread?
•
Java
If I understand correctly, by default, Android services run on the main UI thread
However, my problem is that if Service is called in another thread, that is, AsyncTask or new Thread (...). start();, Does the method of service run in the calling thread? Or is it running on the main thread and the service is said to be running?
In other words,
new Thread(new Runnable() { @Overrde public void run() { myAndroidService.doSomething(); } }).start();
Will MyAndroidService#doSomething () be invoked in this new thread?
Solution
Method always runs in the thread that calls it
A method does not actually belong to any thread, so yes, even if the method is defined in your service, it will execute in the asynctask thread, not the main thread running your service
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码