Using MapActivity for MapView Crashes Application only on MarshMallow (6.0 & 6.0.1)

独自空忆成欢 提交于 2020-01-04 02:02:46

问题


i am extending my activity with MapActivity, to implement MapView dynamically, which contains the fragment that displays mapView.

public abstract class BaseHomeActivity extends MapActivity

I have implemented MapView in a fragment as below

@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;
}

Below is CustomMapView class

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; 
    }
}

When i ran the app on Marshmallow Devices (not emulators), the app crashes as soon as it tries to load the BaseHomeActivity (which extends MapActivity).

Below is the crash :

    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

The Problem :

observe the com.google.android.maps.jar in the above native Crash. Since i was using the "Google Maps Android v1 API", When i ported the App from eclipse to Android Studio, (There was no Google API available from 25 & above) i had to use API 26 for few features like JobIntentService etc.

There were compile errors related to MapActivity, which i resolved by adding maps.jar to libs folder and added as dependency.

If i remove the MapActivity and extend my BaseHomeActivity to AppCompatActivity and comment out my map code, app works fine in marshmallow devices.

Any idea how i can make this work with "Google Maps Android v1 API" (have some limitations to use Google Maps Android V2 API) in Marshmallow, as it is working on every other OS version other than Marshmallow.

Thanks in advance.

来源:https://stackoverflow.com/questions/56697628/using-mapactivity-for-mapview-crashes-application-only-on-marshmallow-6-0-6-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!