我正在尝试Icepick
在我们的应用程序上使用库来保存和恢复手机轮换包,但是库文档我找不到保存的好技巧和通过@Parcel
注释实现的类,这是我在页面上找到的简单类
Example
班级:
@Parcel
public class Example {
String name;
int age;
public Example(){ /*Required empty bean constructor*/ }
public Example(int age, String name) {
this.age = age;
this.name = name;
}
public String getName() { return name; }
public int getAge() { return age; }
public String setName(String name) { this.name = name; }
public int setAge(int age ) { this.age = age; }
}
ExampleBundler
班级:
public class ExampleBundler implements Bundler<Object> {
@Override
public void put(String s, Object example, Bundle bundle) {
bundle.putParcelable(s, Parcels.wrap(example));
}
@Override
public Object get(String s, Bundle bundle) {
return Parcels.unwrap(bundle.getParcelable(s));
}
}
好的,现在我该如何使用它Activity
?
这是我尝试保存和恢复的简单代码
public class MainActivity extends BaseActivity {
/* @State(ExampleBundler.class) String message; */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Example example = new Example();
example.setName = "HELLO WORLD";
example.setAge = 99;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
public void onRestoreInstanceState(Bundle inState) {
}
}
你能修复我的代码吗?感谢提前