0

I am using this code to show a flash video, My problem is when I go from vertical to horizontal position, application reloads and video is reset. How can i avoid this. Please advice

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.internalwebview);

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.setWebViewClient(new HelloWebViewClient());
        mWebView.getSettings().setPluginsEnabled(true);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setSupportZoom(true);
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.setInitialScale(ZOOM_LEVEL);
        mWebView.getSettings().setUseWideViewPort(true);

            mWebView.loadUrl(url);

    }
kakopappa
  • 5,023
  • 5
  • 54
  • 73

3 Answers3

2

Add android:screenOrientation="portrait" to the activity in the AndroidManifest.xml. For example:

    <activity android:name=".SomeActivity"
          android:label="@string/app_name"
          android:screenOrientation="portrait">

This will disable the auto-orientation-change otherwise you will had to handle the change yourself

Hazem Farahat
  • 3,790
  • 2
  • 26
  • 42
2

If you haven't already, you could try saving the state of your WebView when the orientation changes by adding a reference to onSaveInstanceState() in your activity:

protected void onSaveInstanceState(Bundle outState) {
  mWebView.saveState(outState);
}

Then resetting it again in your onCreate() method, as follows:

public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.internalwebview);

    if (savedInstanceState != null)
        ((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
 }

Although I'm not quite sure if it works for embedded Flash video as well. See for more information this thread or the Android SDK reference

Community
  • 1
  • 1
Zebaz
  • 1,545
  • 15
  • 11
  • great explanation, but just in case one wonders what happens when an orientation change occurs ... [here's a good breakdown](http://stuffthathappens.com/blog/2008/11/26/android-lifecycle-triggers-part-2/) – taymless May 23 '11 at 14:02
0

Thanks I found the answer by my self.

mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.setWebViewClient(new HelloWebViewClient());
mWebView.loadUrl(url);

and in AndroidManifest.xml

<android:label="@string/app_name"  android:configChanges="keyboardHidden|orientation"  android:theme="@android:style/Theme.NoTitleBar">
kakopappa
  • 5,023
  • 5
  • 54
  • 73