Passing data through intent using Serializable

前端 未结 11 1523
借酒劲吻你
借酒劲吻你 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 13:42

    I use the following method when sending a List via intent:

    List thumbList = new ArrayList<>();
    //Populate ...
    
    Intent intent = new Intent(context, OtherClass.class);
    intent.putExtra("ThumbArray", thumbList.toArray(new Thumbnail[0]));
    //Send intent...
    

    And retrieving it like so:

    Thumbnail[] thumbArr = (Thumbnail[]) getIntent().getSerializableExtra("ThumbArray");
    if (thumbArr != null) {
        List thumbList = Arrays.asList(thumbArr);
    }
    

提交回复
热议问题