Detecting configuration changes in onStop () method without using isChangingConfigurations ()

I am currently writing an Android application using API level 10. I need to detect configuration changes (screen rotation) in a method onStop()

. I cannot use the method isChangingConfigurations()

because it is only available in API level 11 or higher.

How can I manually detect configuration changes in onStop()

?

+3


source to share


1 answer


Could you please explain more deeply your question because I don't see the case here ... I mean onStop (), as you can read here http://developer.android.com/reference/android/app/Activity .html # onStop () is called when your activity is no longer visible to the user. He was never called either. Thus, I cannot see how you are going to detect the UI behavior when your activity is gone.

If you want to detect some UI behavior, you need to declare that in the android: configChanges attribute in the activity declaration in the manifest. You can see the docs here http://developer.android.com/guide/topics/manifest/activity-element.html



In your case (Screen Rotation) you need android: configChanges = "orientation | screenLayout" rotation of the handle orientation screen in prehoneycomb devices and screenLayout for the rest.

So, when you declare that in the activity element and rotate the device, the onConfigurationChanged () method (which you must override) will be called and you can perform your operation inside it. The activity itself will not be recreated and onCreate () will not be called.

-1


source







All Articles