0

When a user taps on a Remote Notification while the App is in the background I want the App to be foregrounded to wherever the user last left it: assuming the app has not been killed by the OS in which case I want it to start with the LAUNCHER Activity.

Is this possible?

Currently when I tap on a notification it always starts with my LAUNCHER Activity regardless of whether I backgrounded the app while on a different Activity.

UPDATE

So I created an Activity specifically for handling the click_action in my notification:

public class NotificationHandlerActivity extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    finish();
  }
}

Then in my Manifest:

<activity android:name="com.testing.NotificationHandlerActivity" android:screenOrientation="portrait" >
     <intent-filter>
          <action android:name="myAction" />
          <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

Finally when I send the notification I set the click action:

click_action="myAction"

So this works well. When the app is background and I tap on the notification it appears like I'm taken back to where I left off; which is what I want.

The problem now is that when the app is swiped away clicking on the notification does not do anything: since the Activity goes away and there is nothing underneath it.

So the question is: is this a good approach? If so, how could I get around the issue of tapping on a notification when the app is not running in the background?

Przemek Lach
  • 1,348
  • 2
  • 19
  • 42
  • You can send a data notification, then read that data notification in your FirebaseMessagingService subclass and create custom notification with different launch activity as below : https://stackoverflow.com/questions/42731814/how-to-open-specific-activity-after-clicking-on-notification **Update :** Have a look at launchMode attribute, incase it helps you : https://inthecheesefactory.com/blog/understand-android-activity-launchmode/en – Jo Dar Gaya Woh Mar Gaya Jul 30 '18 at 21:00
  • So I have the opposite requirement. I don't want to open a specific Activity. I just want it to bring the App to the foreground where the user left off. – Przemek Lach Jul 30 '18 at 21:07
  • I tried playing around with the modes and they all appear to do the same thing: start with the first Activity. I am missing something obvious here? Like to me this is a easy happy path scenario: tap on notification => bring app to foreground where it was left off. – Przemek Lach Jul 31 '18 at 16:56

0 Answers0