画面を更新する必要なく、アクティビティから戻ることを実装しようとしています。私が見る限り、処理できる状態は 4 つあります。
- [ワイヤレス ネットワークを使用する] と [GPS 衛星を使用する] の両方が無効になっています (ユーザーは [現在地] 設定に移動し、どちらかが無効になっていると続行できません)
- これら 2 つのうちの 1 つが有効になっています (2 つの可能性のうちの 1 つ) 3、両方が有効になっています
私の問題は、アプリの他のアクティビティから戻った後、毎回 setupWebView() が呼び出され、画面の更新が遅れることです。
更新は、設定から戻る必要があります (たとえば、GPS を有効にした後は修正されます) が、アクティビティから戻った後は、画面の再描画の時間の遅延が気を散らし、アプリのワークフローを遅くするため、確かにそうではありません。
すべての setupWebview 呼び出しを回避するために、 onResume() 内でこれを処理する方法を教えてください。
メイン アクティビティ内の 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();
}