我从数据库更新它的值后,我的settext不更新。但是,如果我注销并登录到我的应用程序,则会刷新settext。通过SharedPreferences获得settext的值。
公共类MySettingsActivity扩展了AppCompatActivity {
private TextView settingsDisplayName;
private TextView settingsDisplayStatus;
private User user = SharedPrefManager.getInstance(this).getUser();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_settings);
settingsDisplayName = (TextView) findViewById (R.id.settings_username);
settingsDisplayStatus = (TextView) findViewById(R.id.settings_status);
settingsChangeUsername.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String old_name = settingsDisplayName.getText().toString();
Intent usernameIntent = new Intent(MySettingsActivity.this, UsernameActivity.class);
usernameIntent.putExtra("user_name",old_name );
startActivity(usernameIntent);
}
});
}
@Override
protected void onStart() {
MySettingsActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
settingsDisplayName.setText(user.getName());
settingsDisplayStatus.setText(user.getEmail());
}
});
super.onStart();
}
}