2010-12-05 13 views
0

私は、アクティビティから画面をリフレッシュせずに戻ることを実装しようとしています。 「無線ネットワークを使用」と「GPS機能を使用」は、(ユーザーが現在地の好みに導かれ、いずれかがある場合、継続することはできません無効になっている両アクティビティから復帰した後にsetupWebView()を呼び出さずにonResume()を呼び出す

  1. を:私の知る限り見るように、処理するための4つの可能な状態がありますこれら二つの
  2. 一つは、(1 2の可能性) 3を有効になっている)無効になっている、どちらも、私の問題は私のアプリでは、他の活動から戻った後、setupWebViewは()するたびに呼び出されていることを

を有効にしています画面のリフレッシュ遅延が発生します。

リフレッシュは環境設定から戻っていく必要があります(たとえば、GPSを有効にした後はGPSを使用します)が、アクティビティから復帰しても画面を再描画する時間が遅くなるため、アプリ。

誰かが私の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(); 
} 

答えて

0

booleanフラグを使用してsetupWebView()への呼び出しをスキップするためにそれを使用する - あなたのonResume()方法で、おそらくコードの最も - それをスキップすることが安全であることが分かっている場合。あなたはstartActivity()に電話をかけて位置の設定画面に行きます。したがって、あなたはsetupWebView()に電話する必要があるかどうかを知っています。

+0

これは意味があります。私はそれを試してみる、ありがとう。 – qubz

関連する問題