Darksymphony
Darksymphony

Reputation: 2683

after onClick() notification opens customactivity, I can't get back to mainactivity

In my app I have MainActivity and let's say another CustomActivity. Normally my app starts with mainActivity, that's ok.

But I am sending a firebase notifications, and what I want is to open CustomActivity after I click the notification.

I think I've managed this, because it works:

  if (getIntent().getExtras() != null) {
        startActivity(new Intent(getApplicationContext() , CustomActivity.class));
        finish();
    }

So when a notification is tapped, it will launch CustomActivity.

However, in my CustomActivity I have a back arrow on the top, and of course it will not work, because CustomActivity was my start activity and the app doesn't know where to return step back...

Please what to do with this? I want to bring the user back to MainActivity if he clicks the back arrow.

The arrow is working if the notification is tapped when the app is running, because the MainActivity lifecycle is still on, but the arrow works not when the app is closed and customActivity is iniciated as first.

Upvotes: 0

Views: 39

Answers (2)

Marcos Vasconcelos
Marcos Vasconcelos

Reputation: 18276

If you redirecting to CustomActivity trough the code you posted from the MainActivity, you can simply DO NOT finish() so it get to the activity stack below CustomActivity and the back arrow work as indeed.

Upvotes: 2

darshan
darshan

Reputation: 4569

You can use ParentActivity tag in Manifest like below -

<activity
        android:name=".CustomActivity"
        android:label="@string/title_activity_display_message"
        android:parentActivityName=".MainActivity" >
        <!-- Parent activity meta-data to support 4.0 and lower -->
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity" />
    </activity>

Upvotes: 2

Related Questions