仅在 MarshMallow(6.0 和 6.0.1)上使用 MapActivity 进行 MapView 会使应用程序崩溃

2024-05-05

我正在使用 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; 
    }
}

当我在 Marshmallow 设备(不是模拟器)上运行该应用程序时,该应用程序在尝试加载 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@framewor[email protected] /cdn-cgi/l/email-protection@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 等一些功能。

存在与 MapActivity 相关的编译错误,我通过将maps.jar 添加到 libs 文件夹并添加为依赖项来解决该错误。

如果我删除 MapActivity 并将 BaseHomeActivity 扩展为 AppCompatActivity 并注释掉我的地图代码,则应用程序在棉花糖设备中可以正常工作。

知道如何在 Marshmallow 中使用“Google Maps Android v1 API”(使用 Google Maps Android V2 API 有一些限制)来实现此功能,因为它可以在 Marshmallow 之外的所有其他操作系统版本上使用。

提前致谢。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

仅在 MarshMallow(6.0 和 6.0.1)上使用 MapActivity 进行 MapView 会使应用程序崩溃 的相关文章

随机推荐