2014-01-31 117 views
1

在我的Android項目中,我有一個MapView(API v2),可以在最近的設備上正常工作(S. Galaxy S3,Google Play Services是最新的),但如果我在舊設備上試用(LG-C550,Google Play服務不是最新的),我會通過一個按鈕來獲取錯誤消息來更新服務。問題在於點擊它後應用程序崩潰。從Google Maps API v2更新Google Play服務中的崩潰MapView

我的堆棧跟蹤:

02-16 06:47:51.537: E/AndroidRuntime(4078): FATAL EXCEPTION: main 
02-16 06:47:51.537: E/AndroidRuntime(4078): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at android.app.ContextImpl.startActivity(ContextImpl.java:648) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at android.content.ContextWrapper.startActivity(ContextWrapper.java:258) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at com.google.android.gms.dynamic.a$5.onClick(Unknown Source) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at android.view.View.performClick(View.java:2552) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at android.view.View$PerformClick.run(View.java:8960) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at android.os.Handler.handleCallback(Handler.java:587) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at android.os.Handler.dispatchMessage(Handler.java:92) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at android.os.Looper.loop(Looper.java:123) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at java.lang.reflect.Method.invokeNative(Native Method) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at java.lang.reflect.Method.invoke(Method.java:521) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634) 
02-16 06:47:51.537: E/AndroidRuntime(4078):  at dalvik.system.NativeStart.main(Native Method) 

的運行時異常來自於谷歌地圖視圖(由庫創建),嘗試啓動谷歌從我的應用程序上下文播放服務更新不FLAG_ACTIVITY_NEW_TASK。

您認爲是否有辦法糾正Google Play庫引發的此異常?

我MapActivity類:

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.RelativeLayout; 

import com.google.android.gms.maps.MapView; 

public class MapActivity extends Activity { 

    private MapView mapView = null; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(new RelativeLayout(getApplicationContext()) { 
      { 
       addView(mapView = new MapView(getApplicationContext()) { 
        { 
         setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 
        } 
       }); 
      } 
     }); 
     mapView.onCreate(savedInstanceState); 
    } 

    @Override 
    protected void onDestroy() { 
     super.onDestroy(); 
     mapView.onDestroy(); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     mapView.onResume(); 
    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 
     mapView.onPause(); 
    } 

    @Override 
    public void onLowMemory() { 
     super.onLowMemory(); 
     mapView.onLowMemory(); 
    } 

    @Override 
    protected void onSaveInstanceState(Bundle outState) { 
     super.onSaveInstanceState(outState); 
     mapView.onSaveInstanceState(outState); 
    } 

} 

回答

1

,我發現我的錯誤與此谷歌論壇主題:https://groups.google.com/d/msg/google-admob-ads-sdk/Nb1kCQB4fJo/m7rQQD9CLIEJ

我不得不放棄活動情境,而不是應用程序上下文創建MapView類的實例:

addView(mapView = new MapView(getApplicationContext()) { 

替換爲:

addView(mapView = new MapView(MapActivity.this) { 

如果Google團隊看到這篇文章,請問您是否可以在您的文檔中將其精確到:https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapView.html?hl=fr#MapView(android.content.Context)?我認爲這非常重要

相關問題