title: logut from navigation drawer to login activity in android
body: <p>I had getting problem in navigation drawer activity, i had created my android project with login activity and navigation drawer activity but when i want to logout from navigation drawer to login activity. i didn't come on it, i had tried everything. following is my code. please help me to solve this.</p>
  <p>activity_home.xml</p>
  <pre><code>    &lt;android.support.v4.widget.DrawerLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:id=&quot;@+id/drawer_layout&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:fitsSystemWindows=&quot;true&quot;
      tools:openDrawer=&quot;start&quot;&gt;
  
      &lt;include
          layout=&quot;@layout/app_bar_home&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot; /&gt;
  
      &lt;android.support.design.widget.NavigationView
          android:id=&quot;@+id/nav_view&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;match_parent&quot;
          android:layout_gravity=&quot;start&quot;
          android:fitsSystemWindows=&quot;true&quot;
          app:headerLayout=&quot;@layout/nav_header_home&quot;
          app:menu=&quot;@menu/activity_home_drawer&quot; /&gt;
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  <p>NavigationDrawer.xml</p>
  
  
  <pre><code>&lt;group android:checkableBehavior=&quot;single&quot;&gt;
      &lt;item
          android:id=&quot;@+id/nav_vehicle_enq&quot;
          android:title=&quot;Vehicle Enquiry&quot; /&gt;
      &lt;item
          android:id=&quot;@+id/nav_my_vehicle&quot;
          android:title=&quot;My Vehicles&quot; /&gt;
      &lt;item
          android:id=&quot;@+id/nav_my_rides&quot;
          android:title=&quot;My Rides&quot; /&gt;
      &lt;item
          android:id=&quot;@+id/nav_licence_details&quot;
          android:title=&quot;Licence Details&quot; /&gt;
      &lt;item
          android:id=&quot;@+id/nav_setting&quot;
          android:title=&quot;Setting&quot; /&gt;
      &lt;item
          android:id=&quot;@+id/nav_help&quot;
          android:title=&quot;Help&quot; /&gt;
      **&lt;item
          android:id=&quot;@+id/nav_logout&quot;
          android:title=&quot;Logout&quot;
          android:onClick=&quot;out&quot;/&gt;**
  
  &lt;/group&gt;
  
  &lt;item android:title=&quot;Communicate&quot;&gt;
      &lt;menu&gt;
          &lt;item
              android:id=&quot;@+id/nav_share&quot;
              android:icon=&quot;@drawable/ic_menu_share&quot;
              android:title=&quot;Share&quot; /&gt;
          &lt;item
              android:id=&quot;@+id/nav_send&quot;
              android:icon=&quot;@drawable/ic_menu_send&quot;
              android:title=&quot;Send&quot; /&gt;
  
      &lt;/menu&gt;
  &lt;/item&gt;
  </code></pre>
  
  <p><strong>Navigation.java</strong></p>
  <pre><code>public class HomeActivity extends AppCompatActivity
          implements NavigationView.OnNavigationItemSelectedListener {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_home);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Snackbar.make(view, &quot;Replace with your own action&quot;, Snackbar.LENGTH_LONG)
                          .setAction(&quot;Action&quot;, null).show();
              }
          });
  
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                  this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
          drawer.addDrawerListener(toggle);
          toggle.syncState();
  
          NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
          navigationView.setNavigationItemSelectedListener(this);
      }
  
      @Override
      public void onBackPressed() {
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          if (drawer.isDrawerOpen(GravityCompat.START)) {
              drawer.closeDrawer(GravityCompat.START);
          } else {
              super.onBackPressed();
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.home, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      @SuppressWarnings(&quot;StatementWithEmptyBody&quot;)
      @Override
      public boolean onNavigationItemSelected(MenuItem item) {
          // Handle navigation view item clicks here.
          int id = item.getItemId();
  
          if (id == R.id.nav_vehicle_enq) {
  
  
              // Handle the camera action
          } else if (id == R.id.nav_my_vehicle) {
  
          } else if (id == R.id.nav_my_rides) {
  
  
          } else if (id == R.id.nav_licence_details) {
  
          } else if (id == R.id.nav_share) {
  
          } else if (id == R.id.nav_send) {
  
          } else if (id == R.id.nav_logout) {
  
              Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
              startActivity(intent);
          }
  
          DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          drawer.closeDrawer(GravityCompat.START);
          return true;
      }
  }
  </code></pre>
  <p><strong>manifest.xml</strong></p>
  <pre><code>    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.example.hp.winnersfive&quot;&gt;
  
      &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
  
      &lt;!-- To auto-complete the email text field in the login form with the user's emails --&gt;
      &lt;uses-permission android:name=&quot;android.permission.GET_ACCOUNTS&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.READ_PROFILE&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.READ_CONTACTS&quot; /&gt;
  
      &lt;application
          android:allowBackup=&quot;true&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;
          android:label=&quot;@string/app_name&quot;
          android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
          android:supportsRtl=&quot;true&quot;
          android:theme=&quot;@style/AppTheme&quot;&gt;
          &lt;activity
              android:name=&quot;.LoginActivity&quot;
              android:label=&quot;@string/app_name&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=&quot;.HomeActivity&quot;
              android:label=&quot;@string/title_activity_home&quot;
              android:theme=&quot;@style/AppTheme.NoActionBar&quot; /&gt;
          &lt;activity android:name=&quot;.RegisterActivity&quot; /&gt;
          &lt;activity android:name=&quot;.vehicle_enquiryActivity&quot; /&gt;
  
  
      &lt;/application&gt;
  </code></pre>