简体   繁体   English

OnSaveInstance和OnRetainNonConfigurationInstance之间的区别?

[英]Difference between OnSaveInstance and OnRetainNonConfigurationInstance?

I have an android application and want to save the state of instance in orientation change. 我有一个android应用程序,想在方向更改中保存实例的状态。 My activity contains both primitive datatypes and one user defined arraylist of bitmap and string.Which is the better approch to solve my issue? 我的活动既包含原始数据类型,又包含一个用户定义的位图和字符串数组列表。哪个是解决我的问题的更好方法? what is the difference between OnSaveInstance and OnRetainNonConfigurationInstance? OnSaveInstance和OnRetainNonConfigurationInstance有什么区别?

// 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM