Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does OnResume() in Android makes Activity loading faster?

I was developing an Android Application where I have to load a large data from Android Database and view it on screen.

In earlier stages of development I used to retrieve data from DB in OnCreate() method and it really slowed the start of activity when data became huge. So I called the retrieving of data and viewing it on screen in OnResume() method, so that my app does not crash while taking too long to load it. I know activity is not shown until OnResume is completed.

So is it a good approach to call time taking operations in OnResume instead of having all initialization in OnCreate() method?

like image 846
Lalit Umbarkar Avatar asked Oct 16 '25 14:10

Lalit Umbarkar


1 Answers

So is it a good approach to call time taking operations in OnResume instead of having all initialization in OnCreate() method?

no - you should not do it inside OnCreate or OnResume. You should always do it inside working thread - like AsyncTask.

Any opertion that takes to long to finish, if executed on UI thread will block message queue - this means there are no repaint of UI widgets, user cannot tap on your app to do anything. Everything is blocked until your operation finished. After ~5s Android generates ANR (application is not responding) and kills your app.

like image 192
marcinj Avatar answered Oct 19 '25 11:10

marcinj