react-native-notifications icon indicating copy to clipboard operation
react-native-notifications copied to clipboard

Android receiving in dead state causes app crash

Open WhereBeTheDan opened this issue 9 years ago • 5 comments

I'm encountering a strange issue. If my app is running or in the background, notifications are received normally. If the app isn't running, it does receive the gcm data as usual, but it causes the app to crash (meaning it boots it immediately beforehand?) with the 'Unfortunately, the app has stopped' alert. It does this twice and then gives a 'Service crashed 2 times, stopping' error. Here's the applicable Logcat:

E/dalvikvm(25328): >>>>> com.sagetopia.beahero.android [ userId:0 | appId:10193 ]
I/FA      (25328):   adb shell setprop firebase.analytics.debug-mode com.sagetopia.beahero.android
V/fb-UnpackingSoSource(25328): locked dso store /data/data/com.sagetopia.beahero.android/lib-main
I/fb-UnpackingSoSource(25328): dso store is up-to-date: /data/data/com.sagetopia.beahero.android/lib-main
V/fb-UnpackingSoSource(25328): releasing dso store lock for /data/data/com.sagetopia.beahero.android/lib-main
E/AndroidRuntime(25328): Process: com.sagetopia.beahero.android, PID: 25328
E/AndroidRuntime(25328): 	at com.sagetopia.beahero.android.NotificationsLifecycleFacade.getRunningReactContext(NotificationsLifecycleFacade.java:54)
D/CrashAnrDetector(  656): processName: com.sagetopia.beahero.android
D/CrashAnrDetector(  656): broadcastEvent : com.sagetopia.beahero.android data_app_crash
I/ActivityManager(  656): Waited long enough for: ServiceRecord{436e1df8 u0 com.sagetopia.beahero.android/com.wix.reactnativenotifications.gcm.GcmMessageHandlerService}
I/ActivityManager(  656): Process com.sagetopia.beahero.android (pid 25328) (adj 8) has died.
W/ActivityManager(  656): Service crashed 2 times, stopping: ServiceRecord{436e1df8 u0 com.sagetopia.beahero.android/com.wix.reactnativenotifications.gcm.GcmMessageHandlerService}

I'm also using React Native Navigation and have taken the steps outlined in this repo's wiki. I began this project on react native push notification, but migrated due to the conflicts between RNN and that module.

Here's the full app build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.1'

    defaultConfig {
        applicationId "com.sagetopia.beahero.android"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    ...
}

dependencies {
    compile project(':react-native-notifications')
    compile project(':react-native-navigation')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.facebook.react:react-native:+'
    // From node_modules
    compile('com.google.android.gms:play-services-gcm:10.0.1') {
        force = true;
    }
}

task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

EDIT: This appears to only occur when the app isn't running and the phone is unlocked. However, when locked a notification doesn't cause the phone to wake (That may be normal behavior but wanted to mention it)

WhereBeTheDan avatar Sep 12 '17 19:09 WhereBeTheDan

+1 same problem here RN 0.47 Android React-native-navigation 1.1.215

buffaly avatar Sep 13 '17 04:09 buffaly

I can fix it out with check activity of app try this~

NotificationsLifecycleFacade.java
    @Override
    public ReactContext getRunningReactContext() {
        // check activity of app when dead state
        if (mVisibleActivity == null) {
            return null;
        }

        final ReactGateway reactGateway = NavigationApplication.instance.getReactGateway();
        if (reactGateway == null) {
            return null;
        }
        return reactGateway.getReactContext();
    }

buffaly avatar Sep 28 '17 17:09 buffaly

@buffaly 's comment was very useful for me but still i needed to replace this line if (mVisibleActivity == null) { return null; } with the following if (!isReactInitialized()) { return null; } . I did this because, despite the dead state crash was solved, the app would crash when opening a notification in background.

joaquinTop avatar Jan 05 '18 15:01 joaquinTop

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

stale[bot] avatar Jul 24 '19 22:07 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Jul 31 '19 23:07 stale[bot]