tags:

views:

116

answers:

4

Hi, I have an android application having an AlertDialog with OK and Cancel buttons. When the dialog shows without pressing the OK or Cancel button, just press Home button of device. The Home screen will show. Now open another application suppose Camera. Take some picture or Video. Now get out from the Camera application. Now open my android application and surprisingly the alertdialog have disappeared. Why?

Is there anyone who can help me to solve the problem?

Thanks in advance.

Best Regards, gsmaker

A: 

you mean the alertdialog would appear at start up of your application?

Kandhasamy
did you set your alertdialog as cancelable?
Kandhasamy
A: 

Here is my code:

final AlertDialog.Builder d = new AlertDialog.Builder(this); //d.setTitle(""); d.setMessage("My message"); d.setIcon(icon file id); d.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // progress(); // upDateFileName(MAX_PROGRESS); // some action to be performed } }); d.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // return; } }); d.show();

gsmaker
You should edit your original question rather than post this as an answer.
Andrew Guenther
+2  A: 

I'm guessing you are creating this AlertDialog onCreate() method. First, you should read up on the Activity Lifecycle.

And what happens is that when you go to another app, the Activity goes to onPause method, which cleans up a bit.

Called when the system is about to start resuming a previous activity. This is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, etc. Implementations of this method must be very quick because the next activity will not be resumed until this method returns.

Then because you return to the app, it calls the onResume method, which doesn't create your dialog again.

gogothee
A: 

Go take a look to showDialog method

fedj