I read http://developer.android.com/reference/android/app/Activity.html but I have a question about PreferenceActivity lifecycle:
Does a PreferenceActivity get onStop() or onDestory() call?
I understand it gets onStop() called when user clicks 'Back', but what about onDestory()? when doe开发者_运维知识库s onDesgtory() for PreferenceActivity get called?
Thank you.
As PreferenceActivity
is a subclass of Activity
, it should follow the same lifecycle.
Click on the link you provided and then navigate to Indirect Subclasses or here is the direct http://developer.android.com/reference/android/preference/PreferenceActivity.html
A PreferenceActivity is an Activity and behaves like one. You'll get onPause
as soon as it goes to the background, and onStop
and onDestroy
if it's shut down (or if the configuration changes, like you're changing orientation from portrait to landscape) - they won't typically be called if you're just switching apps.
In general, if you want to apply any changes that were made, you should hook into onPause
.
The default implementation of onBackPressed() calls finish() - which results in onDestroy() being called. PreferenceActivity does not override this method, so onDestroy() should also be called.
This can be verified by checking the link you provided, as well as checking out the source of the API as described in http://androidforums.com/application-development/1045-source-code-android-jar.html
精彩评论