Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes when exiting #11

Open
Orijinn opened this issue Sep 24, 2018 · 0 comments
Open

App crashes when exiting #11

Orijinn opened this issue Sep 24, 2018 · 0 comments

Comments

@Orijinn
Copy link

Orijinn commented Sep 24, 2018

If we use BackHandler.exitApp() on an app not running in Dev mode, the app crashes:

java.lang.RuntimeException:
at android.app.ActivityThread.performDestroyActivity (ActivityThread.java:4247)
at android.app.ActivityThread.handleDestroyActivity (ActivityThread.java:4265)
at android.app.ActivityThread.-wrap6 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1565)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6247)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)
Caused by: java.lang.NullPointerException:
at com.telephony.TelephonyModule.stopListener (TelephonyModule.java:106)
at com.telephony.TelephonyModule.onHostDestroy (TelephonyModule.java:511)
at com.facebook.react.bridge.ReactContext.onHostDestroy (ReactContext.java:230)
at com.facebook.react.ReactInstanceManager.moveToBeforeCreateLifecycleState (ReactInstanceManager.java:714)
at com.facebook.react.ReactInstanceManager.onHostDestroy (ReactInstanceManager.java:623)
at com.facebook.react.ReactInstanceManager.onHostDestroy (ReactInstanceManager.java:637)
at com.facebook.react.ReactActivityDelegate.onDestroy (ReactActivityDelegate.java:119)
at com.facebook.react.ReactActivity.onDestroy (ReactActivity.java:72)
at android.app.Activity.performDestroy (Activity.java:6959)
at android.app.Instrumentation.callActivityOnDestroy (Instrumentation.java:1154)
at android.app.ActivityThread.performDestroyActivity (ActivityThread.java:4234)

I've narrowed it down to the TelephonyModule.stopListener(), however I'm not that good in Android to be sure the fix is ok.
That's my suggestion:

@ReactMethod
    public void stopListener() {
        if(telephonyPhoneStateListener != null)
            telephonyManager.listen(telephonyPhoneStateListener,
                PhoneStateListener.LISTEN_NONE);
        telephonyManager = null;
        telephonyPhoneStateListener = null;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant