开发者

Android webview - starting due to developer command or rotation? how do i tell?

I'm working with a WebView instance so I have html / javascript code which needs to know if its a new display or merely a rotation or similar event. I'm familiar with addJavascriptInterface so getting access to java side content is not a problem.

This question may relate more to the Activity lifecycle - http://developer.android.com/reference/android/app/Activity.html

What methods are unique to the initial loa开发者_JAVA百科ding of the Activity but not subsequent reloads? Or unique to reloading and not the initial load?


I believe you are interested in the configuration changes section of the page you linked to.

The part of interest is this:

Unless you specify otherwise, a configuration change will cause your current activity to be destroyed, going through the normal activity lifecycle process of onPause(), onStop(), and onDestroy() as appropriate...In some special cases, you may want to bypass restarting of your activity based on one or more types of configuration changes. This is done with the android:configChanges attribute in its manifest. For any types of configuration changes you say that you handle there, you will receive a call to your current activity's onConfigurationChanged(Configuration) method instead of being restarted. If a configuration change involves any that you do not handle, however, the activity will still be restarted and onConfigurationChanged(Configuration) will not be called.


Probably you should handle the orientation changes by your self

Manifest:

 android:configChanges="orientation|keyboardHidden"

In your code :

@Override
public void onConfigurationChanged(Configuration newConfig) {
  super.onConfigurationChanged(newConfig);
  setContentView(R.layout.yourLayout);
}

To answer your question here is the android activity lifecycle :

onCreate() -> onSavedInstanceState() -> onStart() -> onResume() -> onRestoreInstanceState() ->onPause() -> onStop() -> onDestroy()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜