You can just re-launch the activity after a successful login. Or, if you are using a separate a different activity for user login, then you can launch the particular activity in whichever you want to get re-directed to. And, that activity will be re-initialized.
If you are worried about persistence factor of user data or, some other user state at that particular moment, you can use saveInstanceState and then sync from it after re-initializing the activity. But, this time the activity will(may) contain some of the logged-in user's information like profile pic, name, gender -etc.
For refreshing the current activity, you can use this below code snippet-
public void refreshActivity (View v){
Intent intent = getIntent();
finish();
startActivity(intent);
}
You can save your current activity state-
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted.
savedInstanceState.putBoolean("MyBoolean", true);
savedInstanceState.putDouble("myDouble", 1.9);
savedInstanceState.putInt("MyInt", 1);
savedInstanceState.putString("MyString", "Welcome back to Android");
// etc.
}
So, you can save your instance state by putting some information as key-value pair relevant to your activity. Then revert it back from the same saved data.
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// Restore UI state from the savedInstanceState.
// This bundle has also been passed to onCreate.
boolean myBoolean = savedInstanceState.getBoolean("MyBoolean");
double myDouble = savedInstanceState.getDouble("myDouble");
int myInt = savedInstanceState.getInt("MyInt");
String myString = savedInstanceState.getString("MyString");
}
I am putting the original answer's
link for your reference. Hope this solves the issue for you.