gpt4 book ai didi

android - 使用 Parcelable 将对象从一个 android Activity 传递到另一个

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:31:11 24 4
gpt4 key购买 nike

我想做这个

class A extends Activity{
private class myClass{
}
myClass obj = new myClass();

intent i = new Intent();
Bundle b = new Bundle();
b.putParcelable(Constants.Settings, obj); //I get the error The method putParcelable(String, Parcelable) in the type Bundle is not applicable for the arguments (int, A.myClass)
i.setClass(getApplicationContext(),B.class);
startActivity(i);
}

如何使用 Parcelable 将 obj 传递给 Activity B?

最佳答案

创建你的类并实现Serializable:

private class myClass implements Serializable  {
}

并喜欢:

myClass obj = new myClass();
Intent aActivity = (A.this, B.class);
intent.putExtra("object", obj);

在接收端:

myClass myClassObject = getIntent().getSerializableExtra("object");  

关于android - 使用 Parcelable 将对象从一个 android Activity 传递到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10975239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com