Maximus
Maximus

Reputation: 285

Dialog dismisses after screen turned on

I have an application where I have an error dialog pop-up. If i do not touch the screen letting the screen dim off, and then turn the screen on,the pop up dialog is no more there. I want the dialog to be there even if the backlight is turned after it goes off, like in other normal android dialogs.

This is how I am creating the dialog

Dialog lVoiceDialog=new AlertDialog.Builder(this).setIcon(
            R.drawable.ic_dialog_alert).setMessage(mVoiceCallMessage)
            .setPositiveButton(R.string.yes, clickListener)
            .setNegativeButton(R.string.no,clickListener1).create();
         lVoiceDialog.setOnDismissListener(dismissListener);

where clickListener and clickListener1 are individual listeners for the positive and negative buttons respectively and dismissListener is listener for running code when the dialog is about to be dismissed.

Please

Upvotes: 1

Views: 983

Answers (4)

dianull
dianull

Reputation: 43

Also, if you for any reason happen to call finish() in onPause() method, getting rid of it can solve the issue.

Upvotes: 0

Kuffs
Kuffs

Reputation: 35661

The other answers make me think I misunderstood the question but just in case..

Your activity is (possibly) being closed when the screen goes off. and restarted when it returns in the normal android activity lifecycle.

To retain your dialog, you would need to save its state when the activity closes and reshow it when it returns.

You can demonstrate this by showing the dialog and rotating the phone. Switching orientation does pretty much the same thing.

Upvotes: 1

jainal
jainal

Reputation: 3021

Why do you need dismissListener?In how many ways your dialog can be closed?if only when user selects 'ok' or cancel then you don't need dismiss listener. if you have to do some task before the dialog closing then you can do it in ok or cancel listener .

Upvotes: 1

Android
Android

Reputation: 2393

use AsyncTask

   @Override
                protected void onPostExecute(Void result) {
                    // TODO Auto-generated method stub
                    super.onPostExecute(result);

                example.dismiss();
}

Upvotes: 1

Related Questions