In my onCreate, the following code executes:
dialog = new ProgressDialog(this);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.setMessage("Welcome! Initializing database... This will take just a minute");
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMax(100);
dialog.setProgress(0);
dialog.show();
The dialog should only go away once an AsyncTask completes. If I click home and then return to the application the ProgressDialog should still be there, and in fact, that’s what happens in the emulator. On my HTC Evo, however, the dialog does not show if I click home and return to the app.
I also have:
@Override
protected void onRestart() {
super.onRestart();
try {
dialog.show();
}
catch(Exception e) {}
}
Any ideas as to what could be causing this?
Updated (most relevant code):
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
RecipeDbAdapter rdAdapter;
int recipesInDb = 0;
// Binds automatically to "@android:id/list"
setContentView(R.layout.country_list);
setListAdapter(new EfficientAdapter(this));
handler = new Handler() {
public void handleMessage(Message msg) {
Bundle b = msg.getData();
String type = b.getString("type");
String data = b.getString("data");
// If message received to advance dialog (called during initial db load)
try {
if (type.equals("dialog")) {
dialog.incrementProgressBy(Integer.parseInt(data));
if (dialog.getProgress() >= dialog.getMax()) {
dialog.setProgress(dialog.getMax());
currentlyLoadingFromDb = false;
dialog.dismiss();
dialog = null;
}
} else if (type.equals("update")) {
updateLastRecipeUpdateDate();
}
} catch (Exception e) {
}
}
};
try {
rdAdapter = new RecipeDbAdapter(Countries.this);
rdAdapter.open();
recipesInDb = rdAdapter.fetchAllRecipesCount();
rdAdapter.close();
// Initialize database of recipes
if (recipesInDb == 0) {
currentlyLoadingFromDb = true;
dialog = new ProgressDialog(this);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.setMessage("Welcome! Initializing database of recipes... This will take just a minute");
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMax(100);
dialog.setProgress(0);
dialog.show();
updateLastRecipeUpdateDate();
loadAT = new LoadDatabaseTask().execute("");
}
rdAdapter.close();
} catch (Exception e) {
}
}
@Override
protected void onPause() {
try {
dialog.dismiss();
}
catch(Exception e) {}
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
if (dialog!=null)
try {
dialog.show();
}
catch(Exception e) {}
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
`
your not restarting the application are you? if the async task is still going i assume that your app was just paused and will go through onResume instead. onResume should show it and onPause should dismiss it, if not create a taskbar notifier.