檢索序列化對象時,在我的應用程序越來越選中鑄警告我有了一個名爲型mSelectedContacts
一個成員變量,它是活動狀態的一部分的活動,所以我將其保存在onSaveInstanceState()
像這如何避免捆綁
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putSerializable(STATE_SELECTED_CONTACTS, mSelectedContacts);
super.onSaveInstanceState(savedInstanceState);
}
當重新創建活動,我得到存儲的Hashset像這樣。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null &&
savedInstanceState.containsKey(STATE_SELECTED_CONTACTS)) {
mSelectedContacts = (HashSet<Integer>)
savedInstanceState.getSerializable(STATE_SELECTED_CONTACTS);
} else
mSelectedContacts = new HashSet<Integer>();
...
現在能正常工作,但它會產生一個未經檢查的鑄警告(從了java.io.Serializable到java.lang.Integer中)。有沒有其他的方法可以將一個可序列化的對象保存到一個包中,然後在沒有得到此警告的情況下檢索它? (除抑制當然:-)吧)
不,我不認爲有任何辦法。我知道的唯一方法是讓序列化採用一個Integer的泛型。但是,顯然我們不能這樣做。所以如果你知道它不會採取任何其他措施,那麼壓制戰鬥是最好的方法。盡我所知 – 2014-12-27 18:23:36