Aju
Aju

Reputation: 4599

How to handle navigation when tapping on notification

I have implemented push notification for the app. When notification is tapped, How to start the application from splash screen if the app is already killed. I want to start from Splash screen if the app is already killed and start from Inside landing screen if the app is already in the background. How to handle this? Please help me.

Upvotes: 0

Views: 649

Answers (2)

mangu23
mangu23

Reputation: 880

Add this code to your create notification method:

        Intent resultIntent = new Intent(this, SplashActivity.class);
        resultIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        resultIntent.setAction(Intent.ACTION_MAIN);
        resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);

Play around with the intent flags [resultIntent.addFlags(/*intent flag here*/)], if you want to:

start from Splash screen if the app is already killed and start from Inside landing screen if the app is already in the background.

Hope this helps!

Upvotes: 3

tk1505
tk1505

Reputation: 312

Use pendingIntent to specify the action which should be performed once the user select the notification. Example tutorial Here

Upvotes: 0

Related Questions