简体   繁体   中英

Difference between OnSaveInstance and OnRetainNonConfigurationInstance?

I have an android application and want to save the state of instance in orientation change. 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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