I have an activity that listens to preference changes and reloads the app. I am using recreate()
to do that. But I don't know how to pass in arguments through that, so I have resorted to manual activity reloading.
Intent intent = getIntent();
finish();
// add in the arguments as Extras to the intent
startActivity(intent);
This has the behaviour I want, but the recreating of the activity isn't smooth for the user as they will see the activity being killed and the same activity relaunching. I want the user to not be aware that the activity was relaunched. So, my question is can I use the method recreate()
and still pass arguments through it.
You can set the data on the activity's intent before calling recreate
getIntent().putExtra("RECREATE_DATA", "Some Data");
recreate()
since when you recreate the activity the same activity instance is used, the data in the intent will still be there after recreate.
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