共享电流。我如何确保帐户保持不变?

发布于 2025-02-07 13:54:11 字数 1388 浏览 2 评论 0原文

我已经在数据库中创建了用户,名称和密码。然后将用户名传递给下一个活动。在菜单中的下一个活动中,您可以单击“注销”按钮,并应显示“注册”窗口。但是对我无济于事,“退出”按钮不会翻转到另一个屏幕,而只是进入同一屏幕...

mSettings = getSharedPreferences("my_storage", Context.MODE_PRIVATE);
editor = mSettings.edit();

if(mSettings.getBoolean("is_logged", true)){
    startActivity(new Intent(Authorisation.this, Menu.class));
    finish();
}

editor.putBoolean("is_logged", false).apply();

然后,我将名称和密码传递给编辑器,将值设置为true。我哪里出错了?

Boolean checkuserpass = DB.checkusernamepassword(user, pass);
if(checkuserpass == true){
    Intent intent  = new Intent(getApplicationContext(), Menu.class);
    intent.putExtra("name", user);
    NAME = user;

    editor.putString(NAME, user).apply();
    editor.putString("PASSWORD", pass).apply();
    editor.putBoolean("is_logged", true).apply();
    startActivity(intent);

另一个菜单活动的代码。在这里,我试图将值传递给标题(用户名 - 注册期间的名称)。

@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    int id = item.getItemId();
    Intent intent = new Intent(Menu.this, Authorisation.class);
    Authorisation authorisation = new Authorisation();
    authorisation.log_out();
    startActivity(intent);
    finish();
    return true;
}

I have already created users, a name and password in my database. Then the user name is passed to the next activity. And with the next activity from the menu, you can click the logout button and it should display the registration window. But nothing works for me, the "exit" button does not flip to another screen, but just goes into the same one...

mSettings = getSharedPreferences("my_storage", Context.MODE_PRIVATE);
editor = mSettings.edit();

if(mSettings.getBoolean("is_logged", true)){
    startActivity(new Intent(Authorisation.this, Menu.class));
    finish();
}

editor.putBoolean("is_logged", false).apply();

and after that, I pass the name and password to the editor, set the value to true. Where did I go wrong?

Boolean checkuserpass = DB.checkusernamepassword(user, pass);
if(checkuserpass == true){
    Intent intent  = new Intent(getApplicationContext(), Menu.class);
    intent.putExtra("name", user);
    NAME = user;

    editor.putString(NAME, user).apply();
    editor.putString("PASSWORD", pass).apply();
    editor.putBoolean("is_logged", true).apply();
    startActivity(intent);

The code of another menu activity. Here I am trying to pass the values to the header (username - name during registration).

@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    int id = item.getItemId();
    Intent intent = new Intent(Menu.this, Authorisation.class);
    Authorisation authorisation = new Authorisation();
    authorisation.log_out();
    startActivity(intent);
    finish();
    return true;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文