【问题标题】:Create app logout event创建应用注销事件
【发布时间】:2017-02-07 04:33:19
【问题描述】:

我正在使用导航抽屉来显示所有项目,例如Setting, Profile, Contact Us, About Us, Logout,当单击这些项目中的任何一个时,它应该显示在片段或其他活动中。

我尝试创建 Logout Fragment,但使用 Activity 和 Intent 无法正常工作。

单击注销时如何获取,它应该从应用程序中完全注销,就像在任何银行应用程序中一样。

【问题讨论】:

  • 分享你的登出码,不清楚
  • @jainishkapadia 请不要在问题中添加“问候,谢谢”
  • 把你的代码..
  • 是什么让你认为你需要一个完整的 Fragment / Activity 才能退出?
  • 无法发布代码...

标签: android logout navigation-drawer


【解决方案1】:

您不需要为注销创建片段,单击注销只需在代码下方运行

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

【讨论】:

  • 我应该在 NavigationDrawer 中添加这个吗? public boolean onNavigationItemSelected(MenuItem item) { // 处理导航视图项目点击这里。 android.app.Fragment 片段=空; int id = item.getItemId(); if(id== R.id.nav_logout){ ........这里............}
【解决方案2】:

我创建了如下对话框:

    public void logoutDialog() {
        /**
         * Create Alert DialogBuilder */
        final AlertDialog.Builder logoutAlert = new AlertDialog.Builder(this);
        final RowLogoutDialogsBinding logoutDialogsBinding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.row_logout_dialogs, null, false);
        View logoutView = logoutDialogsBinding.getRoot();
        logoutAlert.setView(logoutView);

        /*
         * Create Alert Dialogs */
        final AlertDialog mLogoutDialog = logoutAlert.create();
        mLogoutDialog.setTitle(getString(R.string.logout_dialog_title));
        mLogoutDialog.show();

        /*
         * Layout for dialog */
        setFontFace(logoutDialogsBinding.logoutMessage);
        logoutDialogsBinding.logoutNo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLogoutDialog.dismiss();
            }
        });

        logoutDialogsBinding.logoutYes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLogoutDialog.dismiss();
                AccountAuthenticator.removeAccount(mContext);
                finish();

                // DO OTHER PROCESS OF LOGOUT like clear PREFERENCE, DB

                Toast.makeText(mContext, R.string.string_loggedout_success, Toast.LENGTH_SHORT).show();
            }
        });
    }

通过单击该菜单项,我刚刚打开了该对话框。

case R.id.nav_logout:
    logoutDialogs();
    break;

希望对你有帮助。

【讨论】:

    【解决方案3】:

    希望这个答案对未来有所帮助,

    Intent intent = new Intent(MainActivity.this,Login.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //CLEARS INSTANCES OF ALL YOUR ACTIVITIES
            startActivity(intent);
            finish(); //CLEARS BACKSTACK ACTIVITIES
    

    【讨论】:

      猜你喜欢
      • 2016-09-21
      • 2020-11-02
      • 2013-02-13
      • 2013-05-31
      • 1970-01-01
      • 1970-01-01
      • 2012-02-15
      • 2012-09-17
      • 1970-01-01
      相关资源
      最近更新 更多