简体   繁体   中英

Android Studio - TextView Not updating after change has been made in database

I'm new in this kind of thing and I've encounterd a problem that I cannot find a solution for it, so I've come here to ask for your help.

What I'm trying to do:

  1. Register a new user in database
  2. Check if it works.
  3. Change the user or pass
  4. Display the changed username on app.

Sadly, step 4 doesn't work. Let's say that I register user and password 123, 123. I check them to make sure it works (login from app), logout from app, go to database tables, edit the user to 321 return to app. Login with user 321 and password 123. In MainActivity the display will be the same as the first one , user/pass 123 instead of user 321 and pass 123.

Here is the part that handles the user/pass from MainActivity class

  txtName = (TextView) findViewById(R.id.name); //name
    txtEmail = (TextView) findViewById(R.id.email);
    btnLogout = (Button) findViewById(R.id.btnLogout);
  //  setting toolbar
    Toolbar toolBar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolBar);


    session = new SessionManager(getApplicationContext());

    if (!session.isLoggedIn()) {
        logoutUser();
    }

    String name = AppController.getString(getApplicationContext(), "name"); //name
    String email = AppController.getString(getApplicationContext(), "email");
    txtName.setText(name); //name
    txtEmail.setText(email);

The problem I'm facing is that the username doesn't update after changes have been made to the database

Try to put that code in the onResume method of MainActivity. The onCreate method is not always called when you return to your activity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM