问题描述
我想送一个Intent来启动一个活动。我希望能够修改这一意图。然后,当活动被破坏并重新创建,我想这些修改仍然是present当我打电话 getIntent()
。
目前,修改意图正常工作,只要活动并没有被破坏。如果是,那么当活动被重新创建,它会得到启动它的原意,并没有收到,当它被在第一时间推出可能已经修改的副本。
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 via onRestoreInstanceState()
. 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.
这篇关于永久性修改启动的活动意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!