nt-complete
nt-complete

Reputation: 519

onResume called to early when returning from Settings screen

In my app I check if gps is enabled. If not, I send the user to the Settings screen to enable gps.

In my onResume function, I'm requesting information from a server, which is a bit time consuming, and then goes to my next Activity. I'd prefer the user to be stuck at my screen while the information is retrieved. Instead, what I see is the app sits at the Settings screen frozen while the information is gathered, and then goes directly to my next Activity.

 protected void onResume() {
        if(gpsIsOn()) {
            obtainLocationStuff();
            startActivity(new Intent(splashActivity.this, mainActivity.class));
        } else {
          launchCloseDialog();
        }

    super.onResume();
}

How can I get onResume to be launched when the user is actually returned to my app?

Upvotes: 0

Views: 167

Answers (1)

inazaruk
inazaruk

Reputation: 74790

You can't. You must use background threads for potentially time consuming operations. Read about AsyncTask.

Cross-activity coordination can't be changed (except in some very rare cases). How activities are coordinated is described here. But in that example one activity starts another. This is the opposite of what you have, but should still demonstrate the rules.

Upvotes: 1

Related Questions