javaandroidkotlinandroid-dialog

How to display dialog on any screen (fragment or activity) in android


User is in Fragment/Activity "A"
In the onCreate() of screen "A" i fire some network call on a background thread. User navigates to some other Fragment/Activity, now when i get the response from the network i need to show the dialog no matter wherever the user is in the app.



How can i achieve this behavior? using DialogFragment


Solution

  • Create a transparent activity and in its onCreate method show your dialog. Set an OnDismissListener for the dialog and in this callback finish the activity. Every where you need showing your dialog you can start this transparent activity