コード例 #1
0
  public boolean onOptionsItemSelected(MenuItem item) {
    if (drawerToggle.onOptionsItemSelected(item)) return true;

    int id = item.getItemId();
    switch (id) {
      case R.id.logoutMenuItem:
        EMChatManager.getInstance().logout();
        databaseUtil.deleteAllDatabases();
        SharedPreferences.Editor editor =
            getSharedPreferences("login_info", android.content.Context.MODE_PRIVATE).edit();
        editor.putBoolean("state", false);
        editor.commit();
        Intent intent = new Intent(MainActivity.this, StartActivity.class);
        startActivity(intent);
        finish();
        return true;

      case R.id.exitMenuItem:
        MyApplication.finishAllActivity();
        return true;

      default:
        return super.onOptionsItemSelected(item);
    }
  }
コード例 #2
0
  // 抽屉导航的菜单选择
  private boolean onNavigationItemSelected(MenuItem item) {
    Intent intent;
    switch (item.getItemId()) {
        //            case R.id.modifyPersonalInfoMenuItem:
        //                return true;

      case R.id.modifyAccountInfoMenuItem:
        intent = new Intent(MainActivity.this, ModifyAccountInfoActivity.class);
        startActivity(intent);
        return true;

      case R.id.settingMenuItem:
        return true;

      case R.id.logoutMenuItem:
        EMChatManager.getInstance().logout();
        databaseUtil.deleteAllDatabases();
        SharedPreferences.Editor editor =
            getSharedPreferences("login_info", android.content.Context.MODE_PRIVATE).edit();
        editor.putBoolean("state", false);
        editor.commit();
        intent = new Intent(MainActivity.this, StartActivity.class);
        startActivity(intent);
        finish();
        return true;

      case R.id.exitMenuItem:
        MyApplication.finishAllActivity();
        return true;

      case R.id.aboutMenuItem:
        intent = new Intent(MainActivity.this, AboutActivity.class);
        startActivity(intent);
        return true;
    }
    return false;
  }