我正在尝试实现从 Activity 返回而无需刷新屏幕。据我所知,有 4 种可能的状态需要处理:
- “使用无线网络”和“使用 GPS 卫星”都被禁用(用户被定向到“我的位置”首选项,如果其中任何一个被禁用,则不允许继续)
- 这两个启用之一(2 种可能性中的 1 个) 3, 两者都启用
我的问题是,从我的应用程序中的其他活动返回后,每次都会调用 setupWebView() 导致屏幕刷新延迟。
从首选项返回刷新是必要的(例如,启用后的 GPS 得到修复),但肯定不是在从 Activity 返回后,因为重新绘制屏幕的时间延迟会分散注意力并减慢我的应用程序的工作流程。
有人可以建议如何在我的 onResume() 中处理这个问题,以避免所有 setupWebview 调用。
这是我的主要活动中 onResume() 的代码:
@Override
protected void onResume() {
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
&& !locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
createMyLocationDisabledAlert();
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 500, 0, this);
mostRecentLocation = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (mostRecentLocation != null)
setupWebView();
else {
mostRecentLocation = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
setupWebView();
}
}
else if (locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 500, 0, this);
mostRecentLocation = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (mostRecentLocation != null)
setupWebView();
else {
mostRecentLocation = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
setupWebView();
}
}
// locationManager.requestLocationUpdates(provider, 500, 0, this);
// mostRecentLocation = locationManager.getLastKnownLocation(provider);
// } else
// mostRecentLocation = locationManager
// .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
super.onResume();
}