【发布时间】:2019-05-17 21:35:19
【问题描述】:
在我的 android 项目中,我将一个类定义为“设置”,其中包括全局设置值,我将在许多不同的活动中使用它。所以我想使用 Bundle 通过这个类,我尝试作为 Parcelable 但它不起作用?您能说出最佳做法是什么吗?
这是我的课:
public class Setting{
String set1;
boolean set2;
int set3;
}
这就是我尝试将意图捆绑到另一个活动的方式:
...
Setting sets = new Setting();
sets.set1 = "test";
sets.set2 = true;
sets.set3 = 1;
...
Bundle b = new Bundle();
b.putParcelable("pass_settings", (Parcelable) sets );
【问题讨论】:
-
“所以我想使用 Bundle 传递这个类”——如果这个对象代表全局设置,也许你不应该传递它,而是有一个你使用的单例实例。 “我尝试使用 Parcelable 但它不起作用?” -- 你没有在你的
Setting类上实现Parcelable。
标签: android class android-intent bundle