Reputation: 655
I am using a database to persist the state of a search form. I am using the onPause method to persist the data and the onResume method to restore it. My opinion is that restoring and persisting state should be a blocking operation so I plan to perform the database operations on the UI thread. I know this is generally discouraged but the operations should be quick and I think if they were done asynchronously they could lead to inconsistent UI behaviour.
Any advice
Upvotes: 2
Views: 1213
Reputation: 345
Even if you want the application to not accept user input while the slow operations are being performed, you still don't want to do them in the UI thread. This is for two reasons:
Upvotes: 3
Reputation: 13537
Even if you want it to be a blocking operation, you have to show the user that some thing is happening. Because when the UI thread is blocked, the screen will not respond to any touch operation of the user. Sp, you can have an indefinite progress bar in your onPause()
and onResume()
methods till the persistence and restoration is done.
And obviously you will have to do it in a separate thread. Because if the UI thread is not responding for sometime, android can give the Application Not Working
error.
Upvotes: 0