I have a service running a background thread. What I’d like to do is to
show an AlertDialog initiated from my background thread. I know that
this is not the recommended way of notifying the user and that it
interrupts the workflow (as they can pop-up in any application at any
time) but it’s a suitable way for my use case.
There is a handler registered with the background thread and showing a
Toast notification withing the handler works fine. But after switching
to an AlertDialog nothing happens anymore. My showDialog logic is
silently ignored. No Dialog window appears, no log entry. It’s a bit
strange as I’d expect at least a log entry saying that I’m doing
something wrong or whatever.
Are there any limitations for showing an AlertDialog initiated from a
service background thread? Some people seem to recommend a Dialog themed
Activity to get a similar behavior.
Any clarification or help making it work is greatly appreciated!
Yves
It is possible to open a dialog from a background thread. The trick is to start an activity which looks like a dialog:
Then, to start your activity:
Note that this is asyncrhonous and doesn’t block. If you want to process the result, you’ll have to use startService() and pass a custom activity to indicate a result.
Emmanuel