When app is closed and a notification comes, user clicks it and a specific user's Profile opens up. It has a parent activity (UsersActivity) but in this case when back button in the toolbar is clicked, the app is closed.
Back button is working as expected when user goes to profile activity from UsersActivity.
I want it to go parent activity even app starts with a notification. How can I do that?
here is my manifest:
<activity
android:name=".UsersActivity"
android:parentActivityName=".MainActivity"
>
</activity>
<activity
android:name=".ProfileActivity"
android:parentActivityName=".UsersActivity"
>
This is ProfileActivity:
public class ProfileActivity extends AppCompatActivity {
private Toolbar mToolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
mToolbar = findViewById(R.id.profile_toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_gold_back);
getSupportActionBar().setLogo(R.drawable.ic_logo_v);
getSupportActionBar().setTitle(R.string.app_name);
getSupportActionBar().setSubtitle(R.string.profile_toolbar_title);
Notification's class:
public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String notification_title = remoteMessage.getData().get("title");
String notification_message = remoteMessage.getData().get("body");
String click_action = remoteMessage.getData().get("click_action");
String from_user_id = remoteMessage.getData().get("from_user_id");
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(notification_title)
.setContentText(notification_message);
Intent resultIntent = new Intent(click_action);
resultIntent.putExtra("user_id", from_user_id);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
int mNotificationId = (int) System.currentTimeMillis();
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (mNotifyMgr != null) {
mNotifyMgr.notify(mNotificationId, mBuilder.build());
}
}
}