1
我想通過意圖傳遞一個接口對象。爲什麼我正在獲取Parcelable遇到IOException時試圖通過意圖傳遞接口對象
public interface ILockKeyConfig extends Serializable{
public void onKeyConfigChage();
}
// then I am doing in Activity A
Intent intent = new Intent(LockScreenSettings.this,ButtonCustomization.class);
ILockKeyConfig iLockKeyConfig = new ILockKeyConfig() {
@Override
public void onKeyConfigChage() {
System.out.println("onKeyConfigChage called");
}
};
Object[] keConfig = {lockScreenKeyList.get(position),iLockKeyConfig};
intent.putExtra("KeyConfigObj", keConfig);
startActivity(intent);
//and in Activity B I am doing...
private void getIntentData() {
Object[] KeyConfigObj = (Object[]) getIntent().getSerializableExtra("KeyConfigObj");
keyConfig = (KeyConfig) KeyConfigObj[0];
iLockKeyConfig = (ILockKeyConfig) KeyConfigObj[1];
}
,但上面的代碼我收到以下錯誤:
`06-27 15:18:04.648: E/AndroidRuntime(5483): java.lang.RuntimeException: Parcelable encountered IOException writing serializable object
這是怎麼回事錯在這裏?
你穿越的對象'Intent'必須是'Serializable'或'Parcelable'。 –
但我擴展Serializable在我的界面? – user3782810
哦,我明白了。但是你的實際類是非靜態的內部類,所以它不能在任何其他地方被反序列化,而是在創建它的類實例中。 –