有时当我尝试在我的谷歌地图上调用getCameraPosition时,我会遇到以下异常:
java.lang.OutOfMemoryError: java.lang.String[] of length 1073741824 would overflow
at android.os.Parcel.readStringArray(Parcel.java:1798)
at android.os.StrictMode$ViolationInfo.<init>(StrictMode.java:2200)
at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1738)
at android.os.Parcel.readExceptionCode(Parcel.java:1527)
at android.os.Parcel.readException(Parcel.java:1496)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.getCameraPosition(Unknown Source)
at com.google.android.gms.maps.GoogleMap.getCameraPosition(Unknown Source)
at com.myexample.fakegps.MainActivity$9.onCameraChange(MainActivity.java:1110)
at com.google.android.gms.maps.GoogleMap$7.onCameraChange(Unknown Source)
at com.google.android.gms.maps.internal.zzf$zza.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.IOnCameraChangeListener$Stub$Proxy.onCameraChange(IOnCameraChangeListener.java:93)
at com.google.maps.api.android.lib6.gmm6.api.a.a(Unknown Source)
at com.google.maps.api.android.lib6.gmm6.api.a$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
我知道它因为StrictMode已启用但是当我将我的应用程序转换为系统应用程序时,StrictMode会启用并且我收到此错误(正常应用程序正常运行应用程序运行正常)。
如果我的用户将我的应用移动到系统应用,我添加了以下代码以尝试禁用StrictMode:
private static void disableStrictMode() {
if (Build.VERSION.SDK_INT >= 9) {
doDisableStrictMode();
}
if (Build.VERSION.SDK_INT >= 16) {
//restore strict mode after onCreate() returns.
new Handler().postAtFrontOfQueue(new Runnable() {
@Override
public void run() {
doDisableStrictMode();
}
});
}
}
private static void doDisableStrictMode() {
StrictMode.ThreadPolicy.Builder builder = new StrictMode.ThreadPolicy.Builder(StrictMode.getThreadPolicy());
builder.permitAll();
StrictMode.ThreadPolicy policy = builder.build();
StrictMode.setThreadPolicy(policy);
if (Build.VERSION.SDK_INT >= 11) {
StrictMode.VmPolicy.Builder builder2 = new StrictMode.VmPolicy.Builder(StrictMode.getVmPolicy());
builder2.detectAll();
builder2.penaltyLog();
StrictMode.VmPolicy policy2 = builder2.build();
StrictMode.setVmPolicy(policy2);
}
}
我在onCreate结束时调用此代码但它不起作用,我仍然得到异常,任何想法?