I have an AlertDialog and I only want the next Activity to start after I have click "OK". The problem is in my method, I have local variables attached to my intent and I cannot put in the onCreateDialog method.
//local variable created
ArrayList<String> students = new ArrayList<String>();
for(int i=0; i<studentList.size(); i++){
students.add(studentList.get(i).getName());
}
AlertDialog.Builder alertDialog = new AlertDialog.Builder(
new ContextThemeWrapper(this, R.style.popup_theme));
alertDialog.setTitle("Select Game");
alertDialog.setPositiveButton("3x3", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//I want the new Activity to start only after user clicks ok.
Intent intent=new Intent(getApplicationContext(),NewActivity.class);
//Local variable, undefined, cannot reference
intent.putStringArrayListExtra("students", students);
startActivity(intent);
finish();
return;
}
});
alertDialog.show();
Is there any way I can prevent the code after showDialog()
from running until the user clicks OK? I have local variable that I need to put inside the intent.