onResume在后台或手机睡眠后没有被调用

shm*_*ula 3 android onresume android-fragmentactivity

我有恢复我的应用程序的问题 - 当它被切换到后台因别的东西打开(例如我打电话的意图来打开导航),或者是因为手机睡觉; 返回后(另一个活动关闭或电话被唤醒)我的应用程序仍然在后台,onResume从未被调用(日志中没有错误,没有).为什么会发生这种情况?如何摆脱这种行为,我应该从哪里开始寻找?

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 { . . . }
Run Code Online (Sandbox Code Playgroud)

shm*_*ula 7

这是有史以来最愚蠢的"虫子" - noHistory设定为真.将其重置为false就可以了:

    <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>
Run Code Online (Sandbox Code Playgroud)