1

我正在使用recyclerview-mutiselect在我的应用程序中实现动作模式选择模式。

但是,覆盖 onDestroyActionMode 并添加行 getMultiSelector().clearSelections() 会导致 jni 崩溃。这是什么原因造成的?它可以修复吗?如果是怎么办?

    @Override
    public void onDestroyActionMode(ActionMode actionMode) {
        getMultiSelector().clearSelections();
        getMultiSelector().setSelectable(false);
    }

碰撞:

10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: can't call void android.view.View.setTranslationZ(float) on null object
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]     in call to CallVoidMethodV
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]     from void android.animation.PropertyValuesHolder.nCallFloatMethod(java.lang.Object, long, float)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65] "main" prio=5 tid=1 Runnable
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   | group="main" sCount=0 dsCount=0 obj=0x86fceef0 self=0xb4d08000
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   | sysTid=26194 nice=0 cgrp=apps sched=0/0 handle=0xb6facec8
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   | state=R schedstat=( 2230607509 883371110 3756 ) utm=160 stm=63 core=3 HZ=100
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   | stack=0xbe02d000-0xbe02f000 stackSize=8MB
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   | held mutexes= "mutator lock"(shared held)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   native: #00 pc 00004c58  /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   native: #01 pc 000034c1  /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   native: #02 pc 0025898d  /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+84)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   native: #03 pc 0023bde3  /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+162)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   native: #04 pc 000b24e5  /system/lib/libart.so (art::JniAbort(char const*, char const*)+620)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   native: #05 pc 000b2c15  /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+68)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   native: #06 pc 000b2f2f  /system/lib/libart.so (art::ScopedCheck::CheckVirtualMethod(_jobject*, _jmethodID*)+438)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   native: #07 pc 000be29b  /system/lib/libart.so (art::CheckJNI::CallVoidMethodV(_JNIEnv*, _jobject*, _jmethodID*, std::__va_list)+82)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   native: #08 pc 00067897  /system/lib/libandroid_runtime.so (???)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   native: #09 pc 00071ff5  /system/framework/arm/boot.oat (Java_android_animation_PropertyValuesHolder_nCallFloatMethod__Ljava_lang_Object_2JF+132)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.animation.PropertyValuesHolder.nCallFloatMethod(Native method)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.animation.PropertyValuesHolder.access$400(PropertyValuesHolder.java:38)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.animation.PropertyValuesHolder$FloatPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:1296)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:952)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.animation.ValueAnimator.animationFrame(ValueAnimator.java:1207)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1248)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:659)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:682)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.view.Choreographer.doCallbacks(Choreographer.java:590)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.view.Choreographer.doFrame(Choreographer.java:559)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.os.Handler.handleCallback(Handler.java:739)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.os.Handler.dispatchMessage(Handler.java:95)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.os.Looper.loop(Looper.java:145)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at android.app.ActivityThread.main(ActivityThread.java:5944)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at java.lang.reflect.Method.invoke!(Native method)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at java.lang.reflect.Method.invoke(Method.java:372)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65]   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
10-23 01:38:05.291 26194-26194/com.vibhinna.avidd A/art: sart/runtime/check_jni.cc:65] 
4

1 回答 1

1

似乎该错误位于onDestroyActionMode. 持有人应该在MultiSelector变得不可选择之前被停用。此解决方法对我有用:

 @Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
    if (menuItem.getItemId()==  R.id.action_delete){

        deleteItems(mMultiSelector.getSelectedPositions());

        // finish actionMode after you've handled selected positions
        // don't clear selections here - they will be cleared in onDestroyActionMode
        actionMode.finish();
        return true;
    }
    return false;
}

@Override
public void onDestroyActionMode(ActionMode actionMode) {
    // don't call super here - leads to crash!
    // clear selections
    mMultiSelector.clearSelections();
    // here we need to change the mIsSelectable property without refreshing all the holders,
    // so we cant use mMultiSelector.setSelectable(false)
    try {
        Field field = mMultiSelector.getClass().getDeclaredField("mIsSelectable");
        if (field != null) {
            if (!field.isAccessible())
                field.setAccessible(true);
            field.set(mMultiSelector, false);
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
}

感谢valeriia-shchukina@github

于 2016-10-23T11:07:19.150 回答