Let's say we have two types of activity: Activity1 and Activity2.
In the Activity1 onClick () method, we have a call to launch Activity 2 if a certain button is pressed:
Intent myIntent = new Intent(Activity1.this, Activity2.class); Activity1.this.startActivity(myIntent);
After finish () is called in Activity2 and Activity1 resumes, I need to open the dialog box in Activity1 as soon as it resumes.
Before that, I simply called showDialog (id) in the same block of the Activity1 onClick () method:
public void onClick(View v) { if(v == addHole){
The problem is that after the resumption of Activity1, the dialog corresponding to END_DIALOG_ID is not displayed, but the screen is darkened and does not respond (as if the dialog was present) until the back key is pressed.
I tried putting the showDialog () call into the Activity1 onResume () and onRestart () methods, but both of them crashed into the program.
I also tried to create an AsyncTask method in Activity2 with a call to showDialog () in onPostExecute (), but the dialog does not appear in Activity2.
private class ShowDialogTask extends AsyncTask<Void, Void, Integer> { protected Integer doInBackground(Void... id) {
Now I'm trying to implement this by calling
Activity1.this.startActivityForResult(myIntent, END_DIALOG_REQUEST);
with the appropriate methods setResult () and onActivityResult () from Activity1, but it seems that there needs to be a better practice to implement this. All I need to do is show the dialog shown after Activity2 completes.
Thanks for any help you can provide.