Logout in action bar
<p>For my application I used a bouton to logout, but now I would like to use the action bar (When user click on logout icon he goes to homepage) and I can't make them live together.</p>

<p>(I'm french, its hard to code because all tuto are in english. So please be patient with me).</p>

<p>Thank you very much.</p>

<p><strong>My button code was :</strong></p>

<pre><code>btn_logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sessionManager.logout();
                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
</code></pre>

<p><strong>My code where I would like to add icon logout :</strong></p>

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_logout) {
            return true;
        }

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

<p><strong>My XML :</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"&gt;

    &lt;item
        android:id="@+id/action_logout"
        android:icon="@android:drawable/ic_lock_power_off"
        android:title="@string/logout"
        app:showAsAction="ifRoom" /&gt;

&lt;/menu&gt;
</code></pre>