0

In my application, user tap a button to go back to home screen by sending a certain intent to startActivity()

But I want to show a Dialog(built by AlertDialogBuilder) after the user goes to home screen. I will call finish() after going to homescreen. How can I do so?

Or in more general, how can I show dialog after calling startActivity to start a activity not belonging to me(now home screen).

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
Bear
  • 5,138
  • 5
  • 50
  • 80

3 Answers3

1

Please look over this

PopUp dialog Android from background thread

as per link

Use the notification system — don't use dialog boxes in place of notifications

If your background service needs to notify a user, use the standard notification system — don't use a dialog or toast to notify them. A dialog or toast would immediately take focus and interrupt the user, taking focus away from what they were doing: the user could be in the middle of typing text the moment the dialog appears and could accidentally act on the dialog. Users are used to dealing with notifications and can pull down the notification shade at their convenience to respond to your message.

What are Android dialog notifications? A guide to create notifications is here: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

Community
  • 1
  • 1
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
0

If u need to show the dialog,why dont u write the code for showing the dialog as the first line after oncreate().And if u want the dialog only after pressing the backbutton to reture to the screen,create a variable,and when pressing the back button,assign a particular value.And in the oncreate,give an if condition which checks whether that particular condition is satisfied.And if it satisfies,then within the if block,write the code for showing the dialog.

Hope u know the code for creating dialogs.If not,just tell me.I will give u the code

DeepakAndroid
  • 137
  • 1
  • 8
0

if you want to show an alertDialog box here i am posting one sample of that

 private void quitApplication(){
    new AlertDialog.Builder(this)
    .setTitle("Exit")
    .setMessage("Abandon this game?")
    .setIcon(android.R.drawable.ic_dialog_alert)
    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
    })
    .setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {}
    })
    .show();
}   

now all you need to do is call this quitApplication function on your button click event. Hope it helps you. :)

Vikas Gupta
  • 1,530
  • 5
  • 21
  • 34