Android submenu: how to go back to previous submenu (or to main menu from submenu)
<p>Beginner is trying to organize his menu... But I have a problem to implement "Back"-option in my submenus. I expect it to lead user automatically to the main menu. But I couldn't find solution. Did anyone has same challenge before?</p>

<p>I use xml for my context menu:</p>

<pre><code>&lt;item
    android:icon="@android:drawable/ic_menu_sort_by_size"
    android:title="Menu"
    android:id="@+id/main_main_menu"
    app:showAsAction="always"&gt;

    &lt;menu&gt;
        &lt;item
            android:id="@+id/goto_main_menu"
            android:orderInCategory="1"
            android:title="@string/action_goto"
            android:icon="@android:drawable/ic_menu_directions"&gt;
            &lt;menu&gt;
                &lt;item
                    android:orderInCategory="1"
                    android:title="New measurment"
                    android:icon="@android:drawable/ic_menu_add"/&gt;
                &lt;item
                    android:orderInCategory="2"
                    android:title="Archive"
                    android:icon="@android:drawable/ic_menu_agenda"/&gt;
                &lt;item
                    android:id="@+id/back_main_menu"
                    android:orderInCategory="3"
                    android:title="Back"
                    android:icon="@android:drawable/ic_menu_revert"/&gt;
            &lt;/menu&gt;
        &lt;/item&gt;

        &lt;item
            android:orderInCategory="4"
            android:id="@+id/logout"
            android:title="@string/action_logout"
            android:icon="@android:drawable/ic_menu_set_as"/&gt;
    &lt;/menu&gt;
&lt;/item&gt;
</code></pre>

<p></p>

<p>I use following code to display my menu:</p>

<pre><code>@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}
</code></pre>

<p>Option click is managed with following code:</p>

<pre><code>@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (id == R.id.back_main_menu) {
        Toast.makeText(MainActivity.this, "Let's go back...", Toast.LENGTH_LONG).show();
                return true;
        }

    if (id == R.id.logout) {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);

    }
    return super.onOptionsItemSelected(item);
}
</code></pre>

<p>What should I add to my code to return back to main menu after clicking "Back"??</p>