I have implemented onRetainNonConfigurationInstance() on one of my Activity to handle android screen orientation. Here is the code :
@Override
public Object onRetainNonConfigurationInstance() {
Log.d("[DEBUG]", "onRetainNonConfigurationInstance : "
+ this.getClass().getName());
MyState state = new MyState();
return state;
}
I then installed the app on an android device. Here is the configuration :
Device : Samsung Nexus S
Android version : 4.0.4
Kernel version : 3.0.8-g6656123android-build@vpbs1 #1
When I debug the app on the phone by changing screen orientation, my onRetainNonConfigurationInstance() method is not called.
Even weird, I have added a log line in the onCreate() method of my Activity. According to the documentation, Android is supposed to re-create the activity when screen orientation happens. So I have something like the following :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylist);
Log.d(Constants.LOG_TAG, "Oncreate : " + this.getClass().getName());
}
But here, the onCreate() method is not called when I change screen orientation on the device.
Have you guyz already experienced this issue ?
In the documentation, they also say that this method is deprecated and that instead I should use something related to Fragments etc. Can it be the reason why I don't have the method called ?
actually, I am implementing for 2.3.3 to 3.0 devices but my test device is 4.0.4 : Can it be the problem ? I thought there were some kind of backward compatibility between Android OS versions.
thanks in advance,
No comments:
Post a Comment