我正在用MapActivity扩展我的活动,以动态实现MapView,其中包含显示mapView的片段。
public abstract class BaseHomeActivity extends MapActivity
我在如下片段中实现了MapView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
rootView = (ViewGroup) inflater.inflate(R.layout.acs_widget_mymap, null);
linearLayout = (LinearLayout) rootView.findViewById(R.id.mymap_widget_LinearLayout02);
if(AppStateObjects.getMapview() == null){
mapView = new CustomMapView(getActivity(), MAP_API_KEY);
}else{
mapView = AppStateObjects.getMapview();
}
this.inflater = inflater;
mapView.setClickable(true);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT);
mapLayout.addView(linearLayout, layoutParams);
mapOverlays = linearLayout.getOverlays();
iconworker = this.getResources().getDrawable(R.drawable.pointer_worker);
iconequipment = getResources().getDrawable(R.drawable.pointer_equipment);
initBroadCastReceiver();
return rootView;
}
下面是CustomMapView类
public class CustomMapView extends MapView
{
// import com.google.android.maps.MapView;
Context context;
private Bitmap windowFrame;
public CustomMapView(Context context, String apiKey)
{
super(context, apiKey);
this.context = context;
}
@Override
public boolean onTouchEvent(MotionEvent ev)
{
int action = ev.getAction();
switch (action)
{
case MotionEvent.ACTION_DOWN:
this.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
super.onTouchEvent(ev);
return true;
}
@Override
protected void dispatchDraw(Canvas canvas)
{
super.dispatchDraw(canvas);
if (windowFrame == null)
{
createWindowFrame();
}
canvas.drawBitmap(windowFrame, 0, 0, null);
}
protected void createWindowFrame()
{
windowFrame = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas osCanvas = new Canvas(windowFrame);
RectF outerRectangle = new RectF(0, 0, getWidth(), getHeight());
RectF innerRectangle = new RectF(0, 0, getWidth(), getHeight());
float cornerRadius = getWidth() / 50f;
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.rgb(18, 42, 71));
osCanvas.drawRect(outerRectangle, paint);
paint.setColor(Color.RED);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
osCanvas.drawRoundRect(innerRectangle, cornerRadius, cornerRadius, paint);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b)
{
super.onLayout(changed, l, t, r, b);
windowFrame = null;
}
}
当我在棉花糖设备(不是模拟器)上运行该应用程序时,一旦尝试加载BaseHomeActivity(扩展了MapActivity),该应用程序就会崩溃。
以下是崩溃:
Fatal signal 11 (SIGSEGV), code 1, fault addr 0x5f53ee4c in tid 22257 (localz.mim)
06-21 08:30:32.781 3658-3658/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-21 08:30:32.781 3658-3658/? A/DEBUG: Build fingerprint: 'samsung/k3gxx/k3g:6.0.1/MMB29K/G900HXXS1CQD2:user/release-keys'
06-21 08:30:32.781 3658-3658/? A/DEBUG: Revision: '10'
06-21 08:30:32.781 3658-3658/? A/DEBUG: ABI: 'arm'
06-21 08:30:32.781 3658-3658/? A/DEBUG: pid: 22257, tid: 22257, name: localz.mim >>> com.axis.localz.mim <<<
06-21 08:30:32.781 3658-3658/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x5f53ee4c
06-21 08:30:32.826 3658-3658/? A/DEBUG: r0 1313900c r1 131105d0 r2 131415e0 r3 0025e97c
06-21 08:30:32.826 3658-3658/? A/DEBUG: r4 0000a3d0 r5 131105d0 r6 12e7fdf0 r7 131415e0
06-21 08:30:32.826 3658-3658/? A/DEBUG: r8 00000001 r9 b4876500 sl 00000000 fp 12d86560
06-21 08:30:32.826 3658-3658/? A/DEBUG: ip 13101790 sp be986d50 lr b34718c3 pc b44417f8 cpsr 20070030
06-21 08:30:32.846 3658-3658/? A/DEBUG: backtrace:
06-21 08:30:32.846 3658-3658/? A/DEBUG: #00 pc 000ea7f8 /system/lib/libart.so (art_quick_imt_conflict_trampoline+7)
06-21 08:30:32.846 3658-3658/? A/DEBUG: #01 pc 000cb8c1 /data/dalvik-cache/arm/system@framework@com.google.android.maps.jar@classes.dex (offset 0x84000)
06-21 08:30:34.341 3658-3658/? A/DEBUG: Tombstone written to: /data/tombstones/tombstone_03
问题:
在上面的本机崩溃中观察com.google.android.maps.jar。由于我使用的是“ Google Maps Android v1 API”,因此当我将应用程序从eclipse移植到Android Studio时(25及以上版本没有可用的Google API),我不得不使用API 26来实现JobIntentService等功能。 / p>
存在与MapActivity相关的编译错误,我通过将maps.jar添加到libs文件夹并添加为依赖项来解决。
如果我删除MapActivity并将BaseHomeActivity扩展到AppCompatActivity并注释掉我的地图代码,则该应用程序在棉花糖设备中运行良好。
在棉花糖中如何使用“ Google Maps Android v1 API”(使用Google Maps Android V2 API有一些限制)的任何想法,因为它可以在除Marshmallow之外的其他所有OS版本上使用。
先谢谢了。