question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] App crash when onCancel is fired a lot of times

See original GitHub issue

Hello,

I might have a little problem with this code (at least, I think):

/**
 * override onCancel method to callback cancel in case of a touch
 * outside of the dialog or the BACK key pressed
 */
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
    @Override
    public void onCancel(DialogInterface dialog) {
        dialog.dismiss();
        response.putBoolean("didCancel", true);
        callback.invoke(response);
    }
});

which could cause this error when I click at multiples times outside the popup:

03-09 17:08:12.354 2798-5915/com.mycompany.myapp E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
  Process: com.mycompany.myapp, PID: 2798
  com.facebook.react.bridge.ObjectAlreadyConsumedException: Receiving map already consumed
      at com.facebook.react.bridge.WritableNativeMap.putBoolean(Native Method)
      at com.imagepicker.ImagePickerModule$2.onCancel(ImagePickerModule.java:141)
      at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1326)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:148)
      at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:185)
      at java.lang.Thread.run(Thread.java:818)
03-09 17:08:12.481 2798-2798/com.mycompany.myapp I/TSLocationManager: - RNBackgroundGeolocationModule#destroy
03-09 17:08:12.526 2798-2809/com.mycompany.myapp W/MessageQueue: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
  java.lang.IllegalStateException: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
      at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
      at android.os.Handler.enqueueMessage(Handler.java:631)
      at android.os.Handler.sendMessageAtTime(Handler.java:600)
      at android.os.Handler.sendMessageDelayed(Handler.java:570)
      at android.os.Handler.sendEmptyMessageDelayed(Handler.java:534)
      at android.os.Handler.sendEmptyMessage(Handler.java:519)
      at android.view.ViewRootImpl.dispatchWindowAnimationStopped(ViewRootImpl.java:6273)
      at android.view.ViewRootImpl$W.onAnimationStopped(ViewRootImpl.java:6842)
      at android.view.IWindow$Stub.onTransact(IWindow.java:244)
      at android.os.Binder.execTransact(Binder.java:453)
03-09 17:08:12.550 2798-2811/com.mycompany.myapp W/MessageQueue: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
  java.lang.IllegalStateException: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
    at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
    at android.os.Handler.enqueueMessage(Handler.java:631)
    at android.os.Handler.sendMessageAtTime(Handler.java:600)
    at android.os.Handler.sendMessageDelayed(Handler.java:570)
    at android.os.Handler.sendMessage(Handler.java:507)
    at android.view.ViewRootImpl.windowFocusChanged(ViewRootImpl.java:6231)
    at android.view.ViewRootImpl$W.windowFocusChanged(ViewRootImpl.java:6736)
    at android.view.IWindow$Stub.onTransact(IWindow.java:156)
    at android.os.Binder.execTransact(Binder.java:453)
03-09 17:08:12.636 2798-2809/com.mycompany.myapp W/MessageQueue: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
  java.lang.IllegalStateException: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
    at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
    at android.os.Handler.enqueueMessage(Handler.java:631)
    at android.os.Handler.sendMessageAtTime(Handler.java:600)
    at android.os.Handler.sendMessageDelayed(Handler.java:570)
    at android.os.Handler.sendMessage(Handler.java:507)
    at android.view.ViewRootImpl.dispatchAppVisibility(ViewRootImpl.java:6218)
    at android.view.ViewRootImpl$W.dispatchAppVisibility(ViewRootImpl.java:6720)
    at android.view.IWindow$Stub.onTransact(IWindow.java:140)
    at android.os.Binder.execTransact(Binder.java:453)
03-09 17:08:12.652 2798-2811/com.mycompany.myapp W/MessageQueue: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
  java.lang.IllegalStateException: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
    at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
    at android.os.Handler.enqueueMessage(Handler.java:631)
    at android.os.Handler.sendMessageAtTime(Handler.java:600)
    at android.os.Handler.sendMessageDelayed(Handler.java:570)
    at android.os.Handler.sendMessage(Handler.java:507)
    at android.os.Message.sendToTarget(Message.java:416)
    at android.view.ViewRootImpl.dispatchWindowAnimationStarted(ViewRootImpl.java:6268)
    at android.view.ViewRootImpl$W.onAnimationStarted(ViewRootImpl.java:6834)
    at android.view.IWindow$Stub.onTransact(IWindow.java:238)
    at android.os.Binder.execTransact(Binder.java:453)
03-09 17:08:13.053 2798-5884/com.mycompany.myapp W/MessageQueue: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
  java.lang.IllegalStateException: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
    at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
    at android.os.Handler.enqueueMessage(Handler.java:631)
    at android.os.Handler.sendMessageAtTime(Handler.java:600)
    at android.os.Handler.sendMessageDelayed(Handler.java:570)
    at android.os.Handler.sendEmptyMessageDelayed(Handler.java:534)
    at android.os.Handler.sendEmptyMessage(Handler.java:519)
    at android.view.ViewRootImpl.dispatchWindowAnimationStopped(ViewRootImpl.java:6273)
    at android.view.ViewRootImpl$W.onAnimationStopped(ViewRootImpl.java:6842)
    at android.view.IWindow$Stub.onTransact(IWindow.java:244)
    at android.os.Binder.execTransact(Binder.java:453)

Do you have an idea of what’s can cause that? Thanks!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
lwhiteleycommented, Mar 28, 2016

This happened to me when i was trying to push the same map to a WritableArray twice by mistake in a loop.

for eg.

Bad code:

WritableArray array = Arguments.createArray();
WritableMap map = Arguments.createMap();
    while (condition) {
      map.putString("somevalue", value);
      array.pushMap(map);
    }

The code should have been:

WritableArray array = Arguments.createArray();
    while (condition) {
     WritableMap map = Arguments.createMap();
      map.putString("somevalue", value);
      array.pushMap(map);
    }

As you can see in the bad example, the variable map was not inside the loop and wasnt being recreated on each iteration so it had the same reference.

It seems the WritableArray is aware of the references of the objects and doesn’t allow you to add a map twice.

hope this helps or gives some insight

1reaction
yfukscommented, Apr 6, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do my apps keep crashing on Android, How to fix it
There can be multiple ways in which you can fix an app that keeps crashing on your Android smartphone. 1. Force stop the...
Read more >
App crash after sending message to Firebase Database?
Hi @AhsanUllahRasel yes, the problem with this situation is, previously, sending messages was fine until there was one time an emoji was sent ......
Read more >
Crashes | Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >
Why Do My Apps Keep Crashing on Android? - Avast
This article contains: Why are apps on my Android crashing? How to stop apps from crashing; Avoid annoying app crashes with Avast Cleanup....
Read more >
Help AARP Combat Medicare Fraud - aslanpelet.com
Find more information on . Cancel You are leaving AARP.org and going to the ... iGesShop La App de compra pe APK Download...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found