parcelable encountered ioexception writing serializable object…?

前端 未结 5 657
旧时难觅i
旧时难觅i 2021-01-19 01:43

The code

SngList.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView a, View v, int position, long id) {


        In         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-19 02:38

    According to https://forums.bignerdranch.com/t/challenge-saving-state-notserializableexception-error/8018/5 you should implement or extend some class from Parcelable. In my case I had a DialogFragment with an interface MyCallback extending Serializable. In newInstance(MyCallback callback) builder I used:

    Bundle args = new Bundle();
    args.putSerializable(key, callback);
    

    that led to an exception. Then I rewrote MyCallback to extend Parcelable and also added some methods to a callback when invoked this DialogFragment. At least, it doesn't crash on Home button or screen off.

    Also changed to:

    Bundle args = new Bundle();
    args.putParcelable(key, callback);
    

提交回复
热议问题