MobileFirst-Platform-Developer-Center / PreemptiveLoginAndroid

0 stars 0 forks source link

ProtectedActivity helloLabel TextView bug #4

Open gipic opened 6 years ago

gipic commented 6 years ago

Hi, thanks for sharing this project. I have just found a bug into the file ProtectedActivity.java. If I log-in correctly and wait successStateExpirationSec time (how long is a successful state valid for) and push get balance button, I have to insert credentials too (works fine until now). But if I push login button here, the helloLabel shows the old nickname! This happens because sharedpreferences are setted during onCreate method of ProtectedActivity. To solve this bug I have implemented onResume method to update helloLabel text. Es.

  @Override
    protected void onResume() {
        SharedPreferences preferences = _this.getSharedPreferences(Constants.PREFERENCES_FILE, Context.MODE_PRIVATE);
        JSONObject user = null;
        try {
            user = new JSONObject(preferences.getString(Constants.PREFERENCES_KEY_USER,null));
            TextView prova = (TextView) findViewById(R.id.helloLabel);
            prova.setText(getString(R.string.hello_user, user.getString("displayName")));
        } catch (JSONException e) {
                e.printStackTrace();
        }
        super.onResume();
    }