I want to display a dialog over an activity but still want to interact with background activity to perform something, while the dialog is being displayed. How can this be done?
Use a DialogFragment, which is a fragment that displays a dialog window, floating on top of its activity's window. This fragment contains a Dialog object, which it displays as appropriate based on the fragment's state. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog, so your Activity remains in control.
A Dialog
is still part of the same Activity
. They just use different windows.
Since you haven't posted any code, I'll answer you theoretically that when building you Dialog
, you should keep a reference to the Activity
that holds it. This way you would still be able to communicate with it.
I've found a pretty neat work around for this problem. If you place a transparent view on top of everything you can implement a callback to inject an event into the underlying view, but it doesn't have to be an event it can be any code you want to execute on the background view. I have an open source library that demonstrates this. If you check out my repo at: https://bitbucket.org/warwick/hgdialrepo you will find that this library comes with a demo application. Within this demo app you will find a cog demo. If you examine the code behind the cog demo you will see how this can be achieved.
You could start a new Thread
to perform this action. What I recommend is to implement an AsyncTask
Here's a great tutorial to implement these stuff.