Search code examples
androidandroid-fragmentactivityonresume

onResume not called after app in background or phone sleep


I have problem with resuming my app - when it goes to background due to something else opened (for example I call intent to open a navigation), or because phone sleeps; after return (another activity closed or phone woked up) my app remains in background, on onResume is never called (no errors in log, nothing). Why is this happening and how can I get rid of this behavior, where I should start looking?

public class MainActivity extends ...v4.app.FragmentActivity implements FewMyListeners {
    . . .
    private Locator locator;

@Override
public void onResume() {
    super.onResume();

    try {
        locator = new Locator(this);
    } catch (NoLocationProviderFoundException e) {
        showLocationSettingsDialog();
    }

    refreshLocation();
}

@Override
protected void onPause() {
    if(locator != null) {
        locator.removeUpdates(false);
        locator = null;
    }

    dismissProgressDialog();

    super.onPause();
}
}

public class Locator implements LocationSource, LocationListener { . . . }

Solution

  • It was the most idiotic "bug" ever - noHistory set to true. Reset it to false did the trick:

        <activity
            android:name=".MainActivity"
            android:noHistory="false">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>