【发布时间】:2013-04-19 10:52:57
【问题描述】:
我在恢复我的应用时遇到问题 - 由于其他打开的东西(例如我调用意图打开导航)或手机休眠而进入后台时;返回后(另一个活动关闭或手机唤醒)我的应用程序仍然在后台,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 { . . . }
【问题讨论】:
-
你怎么知道
onResume()没有被调用?我想您已经尝试过从该方法(或由它调用的任何其他方法)中打印一条日志消息。 -
是的,我是这样想的。当我运行我的应用程序时,会正确调用 onResume() (并打印日志)。但在睡眠或移至后台后,什么都没有发生。
-
onPause()执行成功了吗? -
是的,我敢肯定!
-
我看到您正在为您的
Locator类中的 my-location 层实现自定义LocationSource。虽然可能不是问题的原因,但我建议让GoogleMap对象管理其位置提供程序的状态,如docs 中所述。
标签: android android-fragmentactivity onresume