Passing data through intent using Serializable

前端 未结 11 1650
借酒劲吻你
借酒劲吻你 2020-11-22 13:35

I\'ve implemented my class with serializable, but it still didn\'t work.

This is my class:

package com.ursabyte.thumbnail;

import java.io.Serializab         


        
11条回答
  •  借酒劲吻你
    2020-11-22 14:03

    In kotlin: Object class implements Serializable:

    class MyClass: Serializable {
    //members
    }
    

    At the point where the object sending:

    val fragment = UserDetailFragment()
    val bundle = Bundle()
    bundle.putSerializable("key", myObject)
    fragment.arguments = bundle
    

    At the fragment, where we want to get our object:

    val bundle: Bundle? = arguments
        bundle?.let {
            val myObject = it.getSerializable("key") as MyClass
            myObject.memberName?.let { it1 -> showShortToast(it1) }
        }
    

提交回复
热议问题