Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to show the alrert dialog after onDestory()?
    primarykey
    data
    text
    <pre><code> package com.example.test3; import java.util.HashMap; import android.os.Bundle; import android.app.Activity; import android.app.AlertDialog; import android.app.DialogFragment; import android.app.FragmentManager; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class Test3 extends Activity { Button testShowPinDialogButton; public AlertDialog alertCreate; AlertDialog.Builder alert; private HashMap&lt;String, Boolean&gt; pinDialogState; EditText input; Context context; private String tag = "Test3"; private String click1 = "click1"; private SharedPreferences sharedPreferences; private SharedPreferences.Editor editor; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test3); context = this; sharedPreferences = getPreferences(MODE_PRIVATE); editor = sharedPreferences.edit(); testShowPinDialogButton = (Button) findViewById(R.id.testShowPinDialogBbutton); testShowPinDialogButton.setOnClickListener(showPinDialog); pinDialogState = new HashMap&lt;String, Boolean&gt;(); Log.d(tag, "onCreate()"); } private OnClickListener showPinDialog = new OnClickListener() { @Override public void onClick(View v) { launchDialog(); } }; @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_test3, menu); return true; } protected void launchDialog() { alert = new AlertDialog.Builder(context); alert.setTitle("Title"); alert.setMessage("Message"); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); pinDialogState.put("click1", false); } }); Log.d(tag, "launchDialog()"); alertCreate = alert.create(); alertCreate.show(); } @Override protected void onPause() { super.onPause(); Log.d(tag, "onPause()"); if (alertCreate != null) { alertCreate.dismiss(); editor.putBoolean(click1, true); } } @Override protected void onRestart() { super.onRestart(); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); Log.d("Test3", "onResume()"); alertCreate.show(); } @Override protected void onDestroy() { super.onDestroy(); Log.d("Test3", "onDestroy()"); } } </code></pre> <p>I am struggling with the logic of how to re-show my alert dialog after it has been dismissed from the onPause(). I was thinking about shared preferences but how would I know that the dialog was being shown before the activity got destroyed and now that the user is coming back into the app, I have to show the dialog. I have also heard that simply calling alertDialog.show() will not work after the activity has been destroyed. What can I do? Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload