androidcold-start

Android app behave abnormal while fetching data


In my android app, I see that whenever i open it for the first time so it load the data from the Firebase But in the same time if i navigate to my BottomNavigationBar or try to change activity or fragment, Even the progressBar that i display while the data is retrieving get stuck for a very little moment like a movie in 2G internet connection. I really don't like that behaviour And I think it will reduce the users count of my app. I don't know the exact reason behind this scene But maybe this line in logcat shouting out that reason

The application may be doing too much work on its main thread.

I want to know the reason and the solution to get rid of it. I have heard about AsyncTask But i don't know it is that or not.


Solution

  • You are doing heavy work you you Main thread. Thats why your applications is frozen. Networking is really heavy job so you have to execute it on separate thread. That is the reason why you se the log The application may be doing too much work on its main thread. The async task is old solution but you can use it. You can use instead executors . But you can use retrofit2 for network requests because they handle thread safety internally. If you are using Kotlin you can use Coroutines.