通过使用序列化的意图传递数据 [英] Passing data through intent using Serializable
本文介绍了通过使用序列化的意图传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我实现了我的类序列化,但它仍然没有奏效。
I've implemented my class with serializable, but it still didn't work.
这是我的类:
package com.ursabyte.thumbnail;
import java.io.Serializable;
import android.graphics.Bitmap;
public class Thumbnail implements Serializable {
private static final long serialVersionUID = 1L;
private String label = "";
private Bitmap bitmap;
public Thumbnail(String label, Bitmap bitmap) {
this.label = label;
this.bitmap = bitmap;
}
public void set_label(String label) {
this.label = label;
}
public String get_label() {
return this.label;
}
public void set_bitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
public Bitmap get_bitmap(){
return this.bitmap;
}
// @Override
// public int compareTo(Thumbnail other) {
// if(this.label != null)
// return this.label.compareTo(other.get_label());
// else
// throw new IllegalArgumentException();
// }
}
这就是我要路过。
List<Thumbnail> all_thumbs = new ArrayList<Thumbnail>();
all_thumbs.add(new Thumbnail(string, bitmap));
Intent intent = new Intent(getApplicationContext(), SomeClass.class);
intent.putExtra("value", all_thumbs);
但仍然没有奏效。我不知道如何使用Parcelable,所以我用这个代替。
But still it didn't work. I don't know how to use Parcelable, so I use this instead.
推荐答案
尝试使用传递序列化的列表<一href="http://developer.android.com/reference/android/os/Bundle.html#putSerializable%28java.lang.String,%20java.io.Serializable%29"相对=nofollow> Bundle.Serializable :
Try to pass the serializable list using Bundle.Serializable:
Bundle bundle = new Bundle();
bundle.putSerializable("value", all_thumbs);
intent.putExtras(bundle);
而在SomeClass的活动得到它的:
And in SomeClass Activity get it as:
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
List<Thumbnail> thumbs=
(List<Thumbnail>)bundle.getSerializable("value");
这篇关于通过使用序列化的意图传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文