Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid - How to show dialog after activity finishes
    primarykey
    data
    text
    <p>Say we have two activities, Activity1 and Activity2.</p> <p>In Activity1's onClick() method, we have a call to start Activity 2 if a certain button is pressed:</p> <pre><code>Intent myIntent = new Intent(Activity1.this, Activity2.class); Activity1.this.startActivity(myIntent); </code></pre> <p>After finish() is called in Activity2, and Activity1 is resumed, I need a dialog to show in Activity1, as soon as it is resumed.</p> <p>Before, I simply called showDialog(id) in the same block of Activity1's onClick() method:</p> <pre><code>public void onClick(View v) { if(v == addHole){ //... Intent myIntent = new Intent(Activity1.this, Activity2.class); Activity1.this.startActivity(myIntent); showDialog(END_DIALOG_ID); } } </code></pre> <p>The issue is, after Activity1 resumes, the dialog corresponding to END_DIALOG_ID is not visible, but the screen is darkened and unresponsive (as if the dialog were present), until the back key is pressed.</p> <p>I have tried putting the showDialog() call in Activity1's onResume() and onRestart() methods, but these both crash the program.</p> <p>I have also tried creating an AsyncTask method in Activity2, with the showDialog() call in its onPostExecute(), but the dialog is not visible in Activity2.</p> <pre><code>private class ShowDialogTask extends AsyncTask&lt;Void, Void, Integer&gt; { /** The system calls this to perform work in a worker thread and * delivers it the parameters given to AsyncTask.execute() */ protected Integer doInBackground(Void... id) { //do nothing return END_DIALOG_ID; } /** The system calls this to perform work in the UI thread and delivers * the result from doInBackground() */ protected void onPostExecute(Integer id) { super.onPostExecute(id); showDialog(id); } } </code></pre> <p>I am now trying to implement this by calling </p> <pre><code>Activity1.this.startActivityForResult(myIntent, END_DIALOG_REQUEST); </code></pre> <p>with corresponding setResult() and onActivityResult() methods from Activity1, but it seems that there should be a better practice for implementing this. All I need is to have a dialog shown upon Activity2 finishing.</p> <p>Thanks for any help you can provide.</p>
    singulars
    1. This table or related slice is empty.
    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