我的 Activity 允许用户选择地理范围,并通过 setResult 函数返回它们:
public class MyActivity extends Activity
.
.
buttonOk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LatLngBounds bounds = map.getProjection().getVisibleRegion().latLngBounds;
Intent result = new Intent();
result.putExtra(RESULT_KEY_MAP_BOUNDS, bounds);
setResult(RESULT_OK, result);
finish();
}
});
调用代码为: . . .
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ACTIVITY_SELECT_GAME_BOUNDS:
if (resultCode == RESULT_OK) {
mapFragment.getView().setVisibility(View.VISIBLE);
LatLngBounds bounds =
data.getExtras().getParcelable(SelectGameBoundsActivity.RESULT_KEY_MAP_BOUNDS);
当我通过 eclipse 运行时,这工作正常,但是当尝试创建 APK(签名或未签名)并在同一设备上运行时,我收到以下错误:
Caused by: android.os.BadParcelableException: Parcelable protocol requires a Parcelable.Creator object called CREATOR on class com.google.android.gms.maps.model.LatLngBounds
这发生在线上:
LatLngBounds bounds =
data.getExtras().getParcelable(SelectGameBoundsActivity.RESULT_KEY_MAP_BOUNDS);
设备正在运行最新的 Google Play 服务。
有什么想法吗?
最佳答案
您可能必须阻止 ProGuard 剥离所需的类。
-keep public class com.google.android.gms.maps.** { public *; }
将此添加到您的 proguard-project.txt 文件中。
关于android - 部署时谷歌地图出现 BadParcelableException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16044715/