我在恢复我的应用程序时遇到了问题-当它由于其他打开的东西而转到后台时(例如,我调用intent打开导航),或者因为手机休眠;在返回之后(另一个活动关闭或手机死机),我的应用程序仍然在后台,在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 { . . . }
发布于 2013-06-12 20:11:52
这是有史以来最愚蠢的"bug“-- 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>
发布于 2013-04-19 10:54:45
确保已在被覆盖的onResume()
方法中调用了super.onResume()
方法
https://stackoverflow.com/questions/16102964
复制相似问题