I have a front screen with a button which opens a second screen. The second screen can take a few seconds to load so I want to display a dialog while loading. My problem is the dialog does not display while loading second screen, but it displays when I return to first page from the second page. If I comment out the "startActivity" to open second page the dialog shows fine. I'm fairly new to android programming - I guess it has something to do with threads.
//code snippet from inside onCreate:
NewGame.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//does not get displayed before 2nd page opens
showDialog(DIALOG2_KEY);
//shows fine if next 2 lines commented out
Intent i = new Intent(screen1.this, SudukuXL.class);
startActivity(i);
I've dealt with the dialog showing on returning to the front screen using onPause(). I've tried using threads to seperate the dialog from the startActivity but I've had no luck. Any help would be appreciated.
I used code from Android examples to create dialog. I include below for reference: protected Dialog onCreateDialog(int id) { switch (id) {
case DIALOG2_KEY: {
ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Loading...");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
return dialog;
}
}
return null;
}