OnSaveInstance和OnRetainNonConfigurationInstance之间的区别?

时间:2011-12-09 03:57:45

标签: android

我有一个Android应用程序,并希望在方向更改中保存实例的状态。我的活动包含原始数据类型和一个用户定义的位图和字符串的arraylist。哪个是解决我的问题的更好的方法? OnSaveInstance和OnRetainNonConfigurationInstance有什么区别?

1 个答案:

答案 0 :(得分:1)

// Just for your first question:
// create a simple class, which include all data what you would like to
// save:
public class DataHolder {
    int a;
    Bitmap b;
    String s;
}

// then return above object at:
Object OnRetainNonConfigurationInstance() {
    DataHolder dh = new DataHolder();
    dh.a = a;
    dh.b = b;

    return dh;
}