Android - Which stream are the fragments?

Are fragments working in a separate thread, than the activity on which they were created?

So, let's say I have a fragment that synchronously calls a web service, does it also block my main view when retrieving data from the server?

+4
source share
2 answers

I would suggest that they are in the UI thread, since Android does such a big job of storing UI actions in the UI thread. When commit() called, these transactions are definitely executed in the user interface thread, as specified in the documentation .

Sounds like you can easily test it with

 Log.d("Fragment", "thread = " + Thread.currentThread().getName()); 

If it is in the "main" thread, then it is in the user interface thread.

+6
source

As stated here, the Android UI is not thread safe, so Snippets work in the same main thread as Activity. Thus, it is better to move the web service call to AsyncTask, otherwise you run the risk of freezing the application.

+10
source

All Articles