O
O
Orkhan Hasanli2018-09-16 13:40:20
Android
Orkhan Hasanli, 2018-09-16 13:40:20

How to return correctly?

Good afternoon!
Let's say there are 2 activities - MainActivity & FavoriteActivity with recyclerview. When clicking on the recyclerview element, the third activity InfoActivity opens.
How to correctly return the user when clicking "Back" depending on which Activity he moved from?
The problem is that in the manifest for an InfoActivity, you can only specify 1 activity as a parent. And of course, the return logic cannot be written in the manifest depending on which activity the user switched from ...

<activity
            android:parentActivityName=".MainActivity">
<meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="info.md7.dermanlar.MainActivity" />
......

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
illuzor, 2018-09-16
@iLLuzor

Handle the up click in code:

override fun onOptionsItemSelected(item: MenuItem): Boolean {
   if (item.itemId == android.R.id.home) finish()
   return super.onOptionsItemSelected(item)
}

E
Egor, 2018-09-18
@RATlius

Create 3 separate Activities.
Start an InfoActivity with the standard startActivity(this, InfoActivity.class) method from two other Activities.
Next, in the Back button handler, call the back button press with NavigationBar onBackPressed()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question