我需要在Bundle中存儲兩個SparseArray。Andriod Bundle with SparseArray <String>
所以在這裏,它是:
protected void onSaveInstanceState(Bundle state) {
super.onSaveInstanceState(state);
state.putSparseParcelableArray("guybrushInsulti", (SparseArray<String>) gameEngine.getDialogs().getInsultKnow());
state.putSparseParcelableArray("guybrushControInsulti",(SparseArray<String>) gameEngine.getDialogs().getControInsultKnow());
state.putSerializable("level", gameEngine.getWorld().getLevel());
}
Eclipse中說:
The method putSparseParcelableArray(String, SparseArray<? extends Parcelable>) in the type Bundle is not applicable for the arguments (String, SparseArray<String>)
OnRestoreInstanceState:
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
SparseArray<String> mInsultiKnow = savedInstanceState.getSparseParcelableArray("guybrushInsulti");
SparseArray<String> mControInsultiKnow = savedInstanceState.getSparseParcelableArray("guybrushControInsulti");
//Ripristino insulti
gameEngine.getDialogs().loadControInsult(mLevel , true);
gameEngine.getDialogs().loadInsult(mLevel, true, mInsultiKnow, mControInsultiKnow);
}
錯誤:
Bound mismatch: The generic method getSparseParcelableArray(String) of type Bundle is not applicable for the arguments (String). The inferred type String is not a valid substitute for the bounded parameter <T extends Parcelable>
我的問題是什麼? :(
檢查這個答案: http://stackoverflow.com/questions/14899718/how-to-store-sparsearray-in-bundle – 2013-04-27 13:43:38
所以我需要延長SparseArray並實現Parcelable? –
Davide
2013-04-27 17:36:11
I'vre創建了'SparseArrayParcelable extends SparseArray implements Parcelable',但Eclipse說: '類型Bundle中的方法putSparseParcelableArray(String,SparseArray <?extends Parcelable>)不適用於參數(String,SparseArrayParcelable)' –
Davide
2013-04-27 17:43:58