1

I have the following question: when I return from one activity to another, I need certain element of menu to be opened. For example:

enter image description here

Now, when I click "Up" in my activity the first element of menu is always opened (where the running man is drawed). And I need to make such element opened, which was opened before opening new activity. For example I choose an article in Articles menu element and after clicking Up in new activity I want to be opened Articles element again. I tried to realize it as clicking on Back button:

@Override
    public boolean onOptionsItemSelected(MenuItem item){
        switch (item.getItemId()){
            case R.id.home:
                this.finish();
                return true;
                default:
                    return super.onOptionsItemSelected(item);
        }

    }

But it didn't help. What's the matter?

Sergei Mikhailovskii
  • 2,100
  • 2
  • 21
  • 43

2 Answers2

0

I think you have to keep the selected item and after returning manually select it. See the example here: https://stackoverflow.com/a/43117486/7469860

0

In your Manifest file, search for your Activity node and add the following line:

android:launchMode="singleTask"

This will define how your activity will be launched.

Here is an official documentation about launchMode property https://developer.android.com/guide/topics/manifest/activity-element#lmode

Gratien Asimbahwe
  • 1,606
  • 4
  • 19
  • 30