AlertDialog以及完成和启动活动导致奇怪的崩溃(segfault)

时间:2017-06-27 20:45:23

标签: android

我有一个项目有时会遇到问题。

以下是问题所在:

UserInterfaceManager uiManager = new UserInterfaceManager(ConnectedDBManagerHost.this);
                if (uiManager.showYesNoDialog(getString(R.string.are_you_sure_you_want_to_disconnect_the_current_database), getString(R.string.are_you_sure), false))
                {
                    ConnectionsManager.connectedDatabase = null;
                    Intent intent = new Intent(this, MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                    finish();
                }

我得到的错误是:

6-27 20:39:30.792 7067-6937/? A/google-breakpad: -----BEGIN BREAKPAD MICRODUMP-----
06-27 20:39:30.792 7067-6937/? A/google-breakpad: V WebView:52.0.2743.100
06-27 20:39:30.792 7067-6937/? A/google-breakpad: O A x86 04 i686 Android/sdk_google_phone_x86/generic_x86:7.1.1/NYC/3756122:userdebug/test-keys
06-27 20:39:30.792 7067-6937/? A/google-breakpad: G OpenGL ES 2.0 (4.5.0 NVIDIA 378.78)|Google (NVIDIA Corporation)|Android Emulator OpenGL ES Translator (GeForce GTX 760/PCIe/SSE2)
06-27 20:39:30.793 7067-6937/? A/google-breakpad: H 12C00000 BF8BF000 0041 15473000 5374A000 0C:0B 0D:06 0E:03 0F:03 11:04 12:04 13:03 14:03 15:03 16:03 17:06 18:06 19:05 1A:03 1C:02
06-27 20:39:30.793 7067-6937/? A/google-breakpad: S 0 BF8BADF0 BF8BA000 00005000
6-27 20:39:30.874 7068-7068/? A/DEBUG: Build fingerprint: 'Android/sdk_google_phone_x86/generic_x86:7.1.1/NYC/3756122:userdebug/test-keys'
06-27 20:39:30.874 7068-7068/? A/DEBUG: Revision: '0'
06-27 20:39:30.874 7068-7068/? A/DEBUG: ABI: 'x86'
06-27 20:39:30.874 7068-7068/? A/DEBUG: pid: 6937, tid: 6937, name: ns.myapp  >>> com.mycompany.myapp <<<
06-27 20:39:30.874 7068-7068/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x57
06-27 20:39:30.874 7068-7068/? A/DEBUG:     eax 00000057  ebx a9237e6c  ecx 7bbc4824  edx 00000000
06-27 20:39:30.874 7068-7068/? A/DEBUG:     esi 7bbc4824  edi 00000000
06-27 20:39:30.874 7068-7068/? A/DEBUG:     xcs 00000073  xds 0000007b  xes 0000007b  xfs 0000003b  xss 0000007b
06-27 20:39:30.874 7068-7068/? A/DEBUG:     eip a922d33e  ebp bf8baf38  esp bf8badf0  flags 00210202
06-27 20:39:31.063 7068-7068/? A/DEBUG: backtrace:
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #00 pc 0001933e  /system/lib/libutils.so (_ZN7android6Looper9pollInnerEi+1262)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #01 pc 00018d84  /system/lib/libutils.so (_ZN7android6Looper8pollOnceEiPiS1_PPv+68)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #02 pc 000d41f3  /system/lib/libandroid_runtime.so (_ZN7android18NativeMessageQueue8pollOnceEP7_JNIEnvP8_jobjecti+77)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #03 pc 000d4264  /system/lib/libandroid_runtime.so
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #04 pc 01d35c9c  /system/framework/x86/boot-framework.oat (offset 0x1584000) (android.os.MessageQueue.nativePollOnce+136)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #05 pc 01d37853  /system/framework/x86/boot-framework.oat (offset 0x1584000) (android.os.MessageQueue.next+223)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #06 pc 01d31c1a  /system/framework/x86/boot-framework.oat (offset 0x1584000) (android.os.Looper.loop+342)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #07 pc 0162b375  /system/framework/x86/boot-framework.oat (offset 0x1584000) (android.app.ActivityThread.main+401)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #08 pc 00109432  /system/lib/libart.so (art_quick_invoke_static_stub+418)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #09 pc 00112de9  /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+313)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #10 pc 005105d5  /system/lib/libart.so (_ZN3artL18InvokeWithArgArrayERKNS_33ScopedObjectAccessAlreadyRunnableEPNS_9ArtMethodEPNS_8ArgArrayEPNS_6JValueEPKc+101)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #11 pc 00512514  /system/lib/libart.so (_ZN3art12InvokeMethodERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectS4_S4_j+1540)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #12 pc 00469530  /system/lib/libart.so (_ZN3artL13Method_invokeEP7_JNIEnvP8_jobjectS3_S3_+96)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #13 pc 005deb9c  /system/framework/x86/boot.oat (offset 0x520000) (java.lang.reflect.Method.invoke+168)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #14 pc 023803d0  /system/framework/x86/boot-framework.oat (offset 0x1584000) (com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run+124)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #15 pc 0238141e  /system/framework/x86/boot-framework.oat (offset 0x1584000) (com.android.internal.os.ZygoteInit.main+1274)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #16 pc 00109432  /system/lib/libart.so (art_quick_invoke_static_stub+418)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #17 pc 00112de9  /system/lib/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+313)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #18 pc 005105d5  /system/lib/libart.so (_ZN3artL18InvokeWithArgArrayERKNS_33ScopedObjectAccessAlreadyRunnableEPNS_9ArtMethodEPNS_8ArgArrayEPNS_6JValueEPKc+101)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #19 pc 00510299  /system/lib/libart.so (_ZN3art17InvokeWithVarArgsERKNS_33ScopedObjectAccessAlreadyRunnableEP8_jobjectP10_jmethodIDPc+393)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #20 pc 003f807e  /system/lib/libart.so (_ZN3art3JNI21CallStaticVoidMethodVEP7_JNIEnvP7_jclassP10_jmethodIDPc+958)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #21 pc 001417d1  /system/lib/libart.so (_ZN3art8CheckJNI11CallMethodVEPKcP7_JNIEnvP8_jobjectP7_jclassP10_jmethodIDPcNS_9Primitive4TypeENS_10InvokeTypeE+4513)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #22 pc 00132f8c  /system/lib/libart.so (_ZN3art8CheckJNI21CallStaticVoidMethodVEP7_JNIEnvP7_jclassP10_jmethodIDPc+108)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #23 pc 00070ad1  /system/lib/libandroid_runtime.so (_ZN7_JNIEnv20CallStaticVoidMethodEP7_jclassP10_jmethodIDz+41)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #24 pc 0007438e  /system/lib/libandroid_runtime.so (_ZN7android14AndroidRuntime5startEPKcRKNS_6VectorINS_7String8EEEb+782)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #25 pc 00001b55  /system/bin/app_process32
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #26 pc 0001532c  /system/lib/libc.so (__libc_init+108)
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #27 pc 0000144c  /system/bin/app_process32
06-27 20:39:31.063 7068-7068/? A/DEBUG:     #28 pc 00000004  <unknown>
06-27 20:39:31.380 1616-7073/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 6600)
06-27 20:39:31.383 1616-7073/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 56)
06-27 20:39:31.385 1616-7073/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 56)
06-27 20:39:31.407 1616-1716/system_process E/ConnectivityService: RemoteException caught trying to send a callback msg for NetworkRequest [ LISTEN id=39, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&FOREGROUND] ]
06-27 20:39:31.407 1616-1716/system_process E/ConnectivityService: RemoteException caught trying to send a callback msg for NetworkRequest [ LISTEN id=40, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&FOREGROUND] ]
06-27 20:39:31.407 1616-1689/system_process E/InputDispatcher: channel '5a5d900 com.mycompany.myapp/com.mycompany.myapp.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
06-27 20:39:31.408 1616-1689/system_process E/InputDispatcher: channel '6fbf281 PopupWindow:15bf3cb (server)' ~ Channel is unrecoverably broken and will be disposed!
06-27 20:39:31.408 1616-1689/system_process E/InputDispatcher: channel 'ccd4cd8 com.mycompany.myapp/com.mycompany.myapp.ConnectedDBManagerHost (server)' ~ Channel is unrecoverably broken and will be disposed!
06-27 20:39:31.408 1616-7073/system_process E/NativeCrashListener: Unable to report native crash
                                                                   java.lang.IndexOutOfBoundsException: Index: 2, Size: 1
                                                                       at java.util.ArrayList.get(ArrayList.java:411)
                                                                       at com.android.server.am.ActivityStack.handleAppCrashLocked(ActivityStack.java:4995)
                                                                       at com.android.server.am.ActivityStackSupervisor.handleAppCrashLocked(ActivityStackSupervisor.java:2885)
                                                                       at com.android.server.am.AppErrors.handleAppCrashLocked(AppErrors.java:590)
                                                                       at com.android.server.am.AppErrors.makeAppCrashingLocked(AppErrors.java:477)
                                                                       at com.android.server.am.AppErrors.crashApplicationInner(AppErrors.java:353)
                                                                       at com.android.server.am.AppErrors.crashApplication(AppErrors.java:305)
                                                                       at com.android.server.am.ActivityManagerService.handleApplicationCrashInner(ActivityManagerService.java:13476)
                                                                       at com.android.server.am.NativeCrashListener$NativeCrashReporter.run(NativeCrashListener.java:86)
06-27 20:39:31.413 7076-7082/? E/art: Failed sending reply to debugger: Broken pipe
06-27 20:39:31.793 1326-1381/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
06-27 20:39:32.599 7076-7162/com.mycompany.myapp E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY)

                                                                            [ 06-27 20:39:32.602  7076: 7162 D/         ]
                                                                            HostConnection::get() New Host Connection established 0x80179280, tid 7162

我想我已经把它缩小到uiManager.showYesNoDialog(),如下所示:

public boolean showYesNoDialog(String message, String title, boolean isCancelable)
    {
        final Handler handler = new Handler()
        {
            @Override
            public void handleMessage(Message mesg)
            {
                throw new RuntimeException();
            }
        };
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCancelable(isCancelable);
        builder.setTitle(title);
            builder.setMessage(message)
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener()
                    {

                        public void onClick(DialogInterface dialog, int which)
                        {
                            dialogResult = true;
                            handler.sendMessage(handler.obtainMessage());
                        }
                    })
                    .setNegativeButton("No", new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                            dialogResult = false;
                            handler.sendMessage(handler.obtainMessage());
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
            try
            {
                Looper.loop();
            }
            catch (RuntimeException ex)
            {
                Log.d("Dialog Error", ex.toString());
            }
        return dialogResult;
    }

上面的方法在我的图书馆中使用,在这个特定的应用程序的许多地方和我们没有任何问题的另一个应用程序。

随着showYesNoDialog被调用我一直得到这个错误(虽然不是每次,但更多时候),但是如果我删除这个方法调用,只是做我不能复制它的意图东西所以我很确定showYesNoDialog方法是问题,但我不明白为什么它在这里有问题,而且没有其他地方。

有没有其他人经历过这样的事情,并且能够阐明我能做些什么来解决这个问题。

1 个答案:

答案 0 :(得分:0)

从CommonsWare评论中得出这一点,Looper.loop是一种不太常见的做事方式。这是我在Android中完成的第一个方法之一,但我没有修复方法来进行回调。

在UserInterfaceManager类中,我添加了以下内容:

public interface IDialogResult
    {
        void returnResult(boolean result);
    }

然后我按如下方式更改了方法:

public void showYesNoDialog(String message, String title, boolean isCancelable, final IDialogResult iDialogResult)
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCancelable(isCancelable);
        builder.setTitle(title);
        builder.setMessage(message)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener()
                {

                    public void onClick(DialogInterface dialog, int which)
                    {
                        iDialogResult.returnResult(true);
                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        iDialogResult.returnResult(false);
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }

该方法调用如下:

uiManager.showYesNoDialog(getString(R.string.are_you_sure_you_want_to_disconnect_the_current_database), getString(R.string.are_you_sure), false, new UserInterfaceManager.IDialogResult()
                {
                    @Override
                    public void returnResult(boolean result)
                    {
                        if (result)
                        {
                            ConnectionsManager.connectedDatabase = null;
                            Intent intent = new Intent(ConnectedDBManagerHost.this, MainActivity.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(intent);
                            finish();
                        }
                    }
                });