Dan
Dan

Reputation: 8784

App not resuming when clicking notification

I have integrated FCM into my app using react-native-firebase

When I background my app and receive a Push Notification, I want my app to resume from the background state.

It appears the onCreate() function from MainActivity is being called because I can see my SplashScreen.

Here's my AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="myapp">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/notification_icon" />
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
        <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <!-- Background Messages (Optional) -->

        <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
    </application>

</manifest>

Upvotes: 3

Views: 459

Answers (1)

Gokul Nath KP
Gokul Nath KP

Reputation: 15553

Set launchMode in your activity to avoid notifications from creating a new Activity instance.

Set launchMode of your SplashScreen to singleInstance.

Refer: https://developer.android.com/guide/topics/manifest/activity-element.html#lmode

Upvotes: 3

Related Questions