简体   繁体   中英

Why is my reference to ProgressDialog wrong after onStop >> onStart?

I create a ProgressDialog in my onStart and then later on, after an async task returns, I hide/dismiss it.

When I jump to the homescreen and back, and re-instantiate a new ProgressDialog to the variable, the code later on still references the old memory address of the last time I set ProgressDialog.

I have tried a multitude of different approaches but I'm stumped. I can't seem to get a ProgressDialog to behave properly after the first start of the app. Could someone guide me in how to fix this, or suggest a different approach?

Thanks.

EDIT: I should mention that I tried using the same variable I set initially, instead of re-instantiating it, but hide/dismiss did nothing.

In onStart()

mProgressDialog = new ProgressDialog(this);
mProgressDialog.show();

Then later in my updateMap()

mProgressDialog.dismiss(); // Or hide()

This works fine the first run. But when the activity is stopped and restarted, the second block does not execute as expected.

EDIT 2:

private ProgressDialog mProgressDialog;

onCreate()

mProgressDialog = new ProgressDialog(this);

onResume()

mProgressDialog.show();

updateMap()

mProgressDialog.hide();

It works the first run, but when the I jump to the homescreen and back, the ProgressDialog never hides. What's going on?!

Try setting the ProgressDialog variable to static. When the activity is recreated, it should reference the same ProgressDialog attached to that activity class, rather than a new one in a new instance of the class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM