I would like send an Intent to start an Activity. I would like to be able to modify that Intent. Then, when the activity is destroyed and recreated, I would like those modifications to still be present when I call getIntent()
.
Currently, modifying the intent works fine as long as the Activity has not been destroyed. If it has, then when the activity is recreated, it will get the original Intent that started it, and not the copy it received when it was launched the first time that may have modified.
This is not the right thing to do it. What you want to do is save data right ? In such a case you don't have to mess with intents, just change the values and then save them, the next time the app runs it will load the values from last time, here is some code:
How to save values:
How to load values:
More info here: developer.android.com/training/basics/data-storage/shared-preferences.html
Try that
Works for me
That's because you are modifying your local copy of the
Intent
, not the master copy maintained in an OS process, where the task lists are kept.If this data is truly instance state of the activity, it should be saved as such, via
onSaveInstanceState()
, and you'd get that back viaonRestoreInstanceState()
. The user of your library would need to forward these events on to you.If you do not wish to consider this to be instance state, but rather process state, store the data in a singleton.
If the data should live beyond the lifetime of a process, write it to disk somewhere.
If by "save the data in the host app's broadcast receiver", that is pointless. A manifest-registered receiver lives for a single broadcast, and then is done.