title: Implement Logout message in built-in back button and logout button
body: <p>This is my MainMenu.java</p>
  
  <pre><code>public class MainMenu extends Activity{
  
      Button userinfo,requestservice,makepayment,trackparcel,checkcard, logout;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main_menu);
          // Show the Up button in the action bar.
          setupActionBar();
          userinfo = (Button) findViewById(R.id.userinfo);
          requestservice = (Button) findViewById(R.id.requestservice);
          makepayment = (Button) findViewById(R.id.makepayment);
          trackparcel = (Button) findViewById(R.id.trackparcel);
          checkcard = (Button) findViewById(R.id.checkcard);
          logout = (Button) findViewById(R.id.logout);
  
          userinfo.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(MainMenu.this, UserInfo.class);              
                  startActivity(intent);
              }
          });
          requestservice.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(MainMenu.this, RequestService.class);
                  startActivity(intent);
  
              }
          });
          makepayment.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(MainMenu.this, Payment.class);
                  startActivity(intent);
  
              }
          });
          trackparcel.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(MainMenu.this, TrackParcel.class);
                  startActivity(intent);
              }
          });
          checkcard.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(MainMenu.this, CheckCard.class);
                  startActivity(intent);
              }
          });
          logout.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(MainMenu.this, Login.class);
                  SharedPreferences userDetails =getSharedPreferences("userdetails", MODE_PRIVATE);
                  Editor edit = userDetails.edit();
                  edit.clear();
                  edit.putString("email", "");
                  edit.putString("password", "");
                  edit.commit();
                  startActivity(intent);
              }
          });
      }
  
      public void dispachBackKey() {
          dispatchKeyEvent(new KeyEvent (KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
          dispatchKeyEvent(new KeyEvent (KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK));
      }
  
      @TargetApi(Build.VERSION_CODES.HONEYCOMB)
      private void setupActionBar() {
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) {
              getActionBar().setDisplayHomeAsUpEnabled(true);
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main_menu, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
          case android.R.id.home:
              // This ID represents the Home or Up button. In the case of this
              // activity, the Up button is shown. Use NavUtils to allow users
              // to navigate up one level in the application structure. For
              // more details, see the Navigation pattern on Android Design:
              //
              // http://developer.android.com/design/patterns/navigation.html#up-vs-back
              //
              NavUtils.navigateUpFromSameTask(this);
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
  
  }
  </code></pre>
  
  <p>I want to trigger the built-in back button and I eventually found this code</p>
  
  <pre><code>public void dispachBackKey() {
      dispatchKeyEvent(new KeyEvent (KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
      dispatchKeyEvent(new KeyEvent (KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK));
  }
  </code></pre>
  
  <p>You may notice that I have logout button as well, What I want to do is that how to display a small message to ask user of the confirmation of logout for <strong>logout button</strong> and <strong>built-in back button</strong>. How should I implement that? </p>