android - How to show progressdialog when the main UI thread is blocked? -
before i'm lampooned, blocking main ui thread, here scenario:
- a service runs once day - takes around 15 secs complete. heavy database transactions
- by coincidence user starts app during time
- the home screen loads data database
- but because database locked (step 1), throws error.
so need freeze ui thread till service completed. no asynctask because ui continue execute , throw error. i've managed put "onresume" function sleep till service finishes. during time i'm unable show dialogs telling user wait or progress bar telling user sit tight.
if try
start onresume if (service running?) show progress dialog while service running, thread.sleep dismiss progress dialog end onresume the thread sleeps fine , wakes great. damn progress dialog doesn't show till onresume...resumes! bottom line, how show indicator (progressdialog or dialog) before put main thread sleep?
i'm open solutions load activity till service resumes. i've tried that, previous activity continues on happily :|
you can not show progress dialog if blocking ui thread.
i guess want invoke dialogue in onresume, ui won't start show dialog before onresume , onpaused done. blocking ui thread in onresume not reached until blocking over. therefor not possible.
you need put waiting in async task , callback ui thread when done. take loading-activity starts actual activity when db update finished.
Comments
Post a Comment