Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Which thread are the fragments running on?

Are fragments running on a separate thread than the activity they were created on?

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

like image 387
aryaxt Avatar asked Dec 05 '22 19:12

aryaxt


1 Answers

As stated here Android UI is not thread safe and so Fragments run in the same main thread as an Activity. As such it's better to move your web-service call into an AsyncTask ar else you are at risk of freezing application.

like image 154
slkorolev Avatar answered Dec 30 '22 01:12

slkorolev