I have the following program flow:
- User fills in form
- My app generates a number of records via a content provider which may take some time (say 10 seconds)
- The user can then continue with the program
I have 2 questions:
-
Why use a non-UI thread to perform step 2 – given that the user can do nothing in my application until this process has been completed, why don’t I just use a waiting widget?
-
If I should use a non UI thread – which type of asynchronous thread approach would make the most sense?
Because you are not the only one using the UI thread. For example, you will be blocking things such as the clock, notifications, etc. And after a few seconds, Android will show an ANR (application not responding dialog), asking the user if they want to wait or kill your app. As for 2, use an
AsyncTask, it makes it easy to do your work and update the UI when done.