I implemented a button in my app that clears all sharedpreferences using this code:
context.getSharedPreferences("bifrostPrefs", 0).edit().clear().commit();
Now the problem is that whenever I use the button, I then need to exit the activity and re-open it to see results. I tried solving this by simply making the button re-open the activity with this code:
Intent reOpen = new Intent (Bifrost.this, Bifrost.class); startActivity(reOpen);
My idea seemed smart until I noticed that if I re-open the activity, I then need to press the back button twice to get back to main activity. So I did some reserach and found this code:
finish(); startActivity(getIntent());
This now works fine, the activity gets refreshed and then I only need to click the back button once. But is there another way to refresh activity without it "flashing" in and out? As you know, everytime you open a new activity, it flashes in and out so the app lags for a second. Is there a way to refresh an activity by bypassing this?
Well, it would be better to update the content of the activity, but if it's too complicated you can override the default animation with this method :
finish(); overridePendingTransition( 0, 0); startActivity(getIntent()); overridePendingTransition( 0, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With