简体   繁体   中英

Reload database value after back button

On my homescreen I am getting a certain value out of my DB (item out table where a field active=1):

String s2 = "Logged in as " + myDbHelper.getActivePlayer();
bPlayQuiz.setText(s2);

When I click to my settings activity, change the player, another player gets field active=1. So when I hit the back button, the first value is still there... Any idea how to code this that it will refresh when I come back on my homescreen?

You can always reload the field in the onResume , which is called whenever the activity regains focus:

@Override
public void onResume()
{
    super.onResume();

    String s2 = "Logged in as " + myDbHelper.getActivePlayer();
    bPlayQuiz.setText(s2);
}

There's more information about the resume part of the lifecycle here .

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