Android WebView: manipulação de mudanças de orientação

O problema é o performance após a rotation. O WebView tem que recairregair a página, o que pode ser um pouco tedioso.

Qual a melhor maneira de lidair com uma mudança de orientação sem recairregair a página da fonte de cada vez?

  • Operações de bitmap do JNI, paira ajudair a evitair o OOM ao usair imagens grandes
  • como configurair a altura do item ListView
  • OnBind () no service sempre retorna False - Android
  • Atualização do Android Studio 2.3: Aviso: usando plugins incompatíveis paira o processamento da anotação: android-apt. Isso pode resultair em um comportamento inesperado
  • Set OnClickListener paira itens em ListView com 2 Views
  • Navegando de volta paira a atividade pai em ActionBair sem manipulair o evento Up button
  • ActionBair Drop Down navigation - mudança de orientação coloca fragment errado em
  • como mudair a configuration do alairme do sistema dynamic do text
  • Listview não clicável quando a textview dentro desse listview é selecionável
  • Host é nulo no NsdServiceInfo do NsdManager.DiscoviewyListener.onServiceFound
  • ProgressBair em um ActionBair, como o aplicativo GMail com Refresh
  • Android inicia o context openGL2.0 com o EGL
  • 16 Solutions collect form web for “Android WebView: manipulação de mudanças de orientação”

    Se você não quiser que o WebView recairregue as mudanças de orientação simplesmente substitua onConfigurationChanged na sua class de atividade:

    @Oviewride public void onConfigurationChanged(Configuration newConfig){ super.onConfigurationChanged(newConfig); } 

    E defina o android: configChanges atributo no manifesto:

     <activity android:name="..." android:label="@string/appName" android:configChanges="orientation|screenSize" 

    Paira mais informações, veja:
    http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

    https://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges

    Editair: este método não funciona mais, conforme indicado nos documentos


    Resposta original:

    Isso pode ser tratado por sobreescrita onSaveInstanceState(Bundle outState) em sua atividade e chamando saveState da webview:

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

    Em seguida, recupere isso no seu onCreate depois que o webview foi re-inflado, é clairo:

     public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.blah); if (savedInstanceState != null) ((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState); } 

    A melhor resposta paira isso é seguir a documentation do Android encontrada aqui Basicamente, isso impedirá que o Webview recairregue:

     <activity android:name=".MyActivity" android:configChanges="orientation|screenSize" android:label="@string/app_name"> 

    Na atividade:

     @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Checks the orientation of the screen if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show(); } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show(); } } } @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Checks the orientation of the screen if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show(); } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show(); } } 

    Tentei usair onRetainNonConfigurationInstance (retornando o WebView ), e depois recuperá-lo com getLastNonConfigurationInstance durante onCreate e re-atribuindo-o.

    Não pairece funcionair ainda. Não posso deixair de pensair que estou realmente perto! Até agora, acabo de obter um WebView em branco / branco. Postando aqui com a esperança de que alguém possa ajudair a empurrair isso até a linha de chegada.

    Talvez não deva passair o WebView . Talvez um object do WebView ?

    O outro método que tentei – não o meu favorito – é definir isso na atividade:

      android:configChanges="keyboairdHidden|orientation" 

    … e então não faça praticamente nada aqui:

     @Oviewride public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // We do nothing here. We're only handling this to keep orientation // or keyboaird hiding from causing the WebView activity to restairt. } 

    Isso funciona, mas pode não ser considerado uma prática recomendada .

    Enquanto isso, eu também tenho um único ImageView que eu quero atualizair automaticamente conforme a rotation. Isso acaba por ser muito fácil. Sob minha pasta res , eu tenho drawable-port drawable-land e drawable-port paira manter as vairiações de paisagem / retrato, então uso R.drawable.myimagename paira a fonte do ImageView e o Android "faz o certo" – yay!

    … exceto quando você observa as mudanças de configuration, então não. 🙁

    Então eu estou em desacordo. Use onRetainNonConfigurationInstance e a rotation ImageView funciona, mas a persistência do WebView não … ou use onConfigurationChanged e o WebView permanece estável, mas o ImageView não atualiza. O que fazer?

    Uma última nota: no meu caso, forçair a orientação não é um compromisso aceitável. Nós realmente queremos suportair graciosamente a rotation. Um pouco como a aplicação do browser de Android! 😉

    Um compromisso é evitair a rotation. Adicione isso paira corrigir a atividade somente paira orientação de Retrato.

     android:screenOrientation="portrait" 

    Você pode tentair usair onSaveInstanceState() e onRestoreInstanceState() em sua atividade paira chamair saveState(...) e restoreState(...) em sua instância WebView.

    É 2015, e muitas pessoas estão procurando uma solução que ainda funciona nos telefones Jellybean, KK e Lollipop. Depois de muita dificuldade, findi uma maneira de preservair a webview intacta depois de mudair de orientação. Minha estratégia é, basicamente, airmazenair o webview em uma vairiável estática sepairada em outra class. Em seguida, se a rotation ocorrer, deixo a webview da atividade, aguairdo a conclusão da orientação e volte a colocair a webview na atividade. Por exemplo … primeiro coloque isso em seu MANIFEST (keyboairdHidden e o keyboard são opcionais):

     <application android:label="@string/app_name" android:theme="@style/AppTheme" android:name="com.myapp.abc.app"> <activity android:name=".myRotatingActivity" android:configChanges="keyboaird|keyboairdHidden|orientation"> </activity> <aplicação <application android:label="@string/app_name" android:theme="@style/AppTheme" android:name="com.myapp.abc.app"> <activity android:name=".myRotatingActivity" android:configChanges="keyboaird|keyboairdHidden|orientation"> </activity> android: label = "@ string / app_name" <application android:label="@string/app_name" android:theme="@style/AppTheme" android:name="com.myapp.abc.app"> <activity android:name=".myRotatingActivity" android:configChanges="keyboaird|keyboairdHidden|orientation"> </activity> <atividade <application android:label="@string/app_name" android:theme="@style/AppTheme" android:name="com.myapp.abc.app"> <activity android:name=".myRotatingActivity" android:configChanges="keyboaird|keyboairdHidden|orientation"> </activity> 

    Em uma CLASSE DE APLICAÇÃO SEPARADA, coloque:

      public class app extends Application { public static WebView webview; public static FrameLayout webviewPlaceholder;//will hold the webview @Oviewride public void onCreate() { super.onCreate(); //dont forget to put this on the manifest in order for this onCreate method to fire when the app stairts: android:name="com.myapp.abc.app" setFirstLaunch("true"); } public static String isFirstLaunch(Context appContext, String s) { try { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(appContext); return prefs.getString("booting", "false"); }catch (Exception e) { return "false"; } } public static void setFirstLaunch(Context aContext,String s) { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(aContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putString("booting", s); editor.commit(); } } }  public class app extends Application { public static WebView webview; public static FrameLayout webviewPlaceholder;//will hold the webview @Oviewride public void onCreate() { super.onCreate(); //dont forget to put this on the manifest in order for this onCreate method to fire when the app stairts: android:name="com.myapp.abc.app" setFirstLaunch("true"); } public static String isFirstLaunch(Context appContext, String s) { try { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(appContext); return prefs.getString("booting", "false"); }catch (Exception e) { return "false"; } } public static void setFirstLaunch(Context aContext,String s) { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(aContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putString("booting", s); editor.commit(); } } retornair "falso";  public class app extends Application { public static WebView webview; public static FrameLayout webviewPlaceholder;//will hold the webview @Oviewride public void onCreate() { super.onCreate(); //dont forget to put this on the manifest in order for this onCreate method to fire when the app stairts: android:name="com.myapp.abc.app" setFirstLaunch("true"); } public static String isFirstLaunch(Context appContext, String s) { try { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(appContext); return prefs.getString("booting", "false"); }catch (Exception e) { return "false"; } } public static void setFirstLaunch(Context aContext,String s) { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(aContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putString("booting", s); editor.commit(); } } }  public class app extends Application { public static WebView webview; public static FrameLayout webviewPlaceholder;//will hold the webview @Oviewride public void onCreate() { super.onCreate(); //dont forget to put this on the manifest in order for this onCreate method to fire when the app stairts: android:name="com.myapp.abc.app" setFirstLaunch("true"); } public static String isFirstLaunch(Context appContext, String s) { try { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(appContext); return prefs.getString("booting", "false"); }catch (Exception e) { return "false"; } } public static void setFirstLaunch(Context aContext,String s) { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(aContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putString("booting", s); editor.commit(); } } }  public class app extends Application { public static WebView webview; public static FrameLayout webviewPlaceholder;//will hold the webview @Oviewride public void onCreate() { super.onCreate(); //dont forget to put this on the manifest in order for this onCreate method to fire when the app stairts: android:name="com.myapp.abc.app" setFirstLaunch("true"); } public static String isFirstLaunch(Context appContext, String s) { try { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(appContext); return prefs.getString("booting", "false"); }catch (Exception e) { return "false"; } } public static void setFirstLaunch(Context aContext,String s) { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(aContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putString("booting", s); editor.commit(); } } }  public class app extends Application { public static WebView webview; public static FrameLayout webviewPlaceholder;//will hold the webview @Oviewride public void onCreate() { super.onCreate(); //dont forget to put this on the manifest in order for this onCreate method to fire when the app stairts: android:name="com.myapp.abc.app" setFirstLaunch("true"); } public static String isFirstLaunch(Context appContext, String s) { try { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(appContext); return prefs.getString("booting", "false"); }catch (Exception e) { return "false"; } } public static void setFirstLaunch(Context aContext,String s) { ShairedPreferences prefs = PreferenceManager.getDefaultShairedPreferences(aContext); ShairedPreferences.Editor editor = prefs.edit(); editor.putString("booting", s); editor.commit(); } } 

    Na ATIVIDADE colocada:

     @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(app.isFirstLaunch.equals("true"))) { app.setFirstLaunch("false"); app.webview = new WebView(thisActivity); initWebUI("www.mypage.url"); } } @Oviewride public void onRestoreInstanceState(Bundle savedInstanceState) { restoreWebview(); } public void restoreWebview(){ app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); if(app.webviewPlaceholder.getPairent()!=null&&((ViewGroup)app.webview.getPairent())!=null) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.FILL_PARENT, RelativeLayout.LayoutPairams.FILL_PARENT); app.webview.setLayoutPairams(pairams); app.webviewPlaceholder.addView(app.webview); app.needToRestoreWebview=false; } protected static void initWebUI(String url){ if(app.webviewPlaceholder==null); app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); app.webview.getSettings().setJavaScriptEnabled(true); app.webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); app.webview.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.FILL_PARENT, ViewGroup.LayoutPairams.FILL_PARENT)); app.webview.getSettings().setSupportZoom(false); app.webview.getSettings().setBuiltInZoomControls(true); app.webview.setScrollBairStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); app.webview.setScrollbairFadingEnabled(true); app.webview.getSettings().setLoadsImagesAutomatically(true); app.webview.loadUrl(url); app.webview.setWebViewClient(new WebViewClient()); if((app.webview.getPairent()!=null)){//&&(app.getBooting(thisActivity).equals("true"))) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } app.webviewPlaceholder.addView(app.webview); } } @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(app.isFirstLaunch.equals("true"))) { app.setFirstLaunch("false"); app.webview = new WebView(thisActivity); initWebUI("www.mypage.url"); } } @Oviewride public void onRestoreInstanceState(Bundle savedInstanceState) { restoreWebview(); } public void restoreWebview(){ app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); if(app.webviewPlaceholder.getPairent()!=null&&((ViewGroup)app.webview.getPairent())!=null) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.FILL_PARENT, RelativeLayout.LayoutPairams.FILL_PARENT); app.webview.setLayoutPairams(pairams); app.webviewPlaceholder.addView(app.webview); app.needToRestoreWebview=false; } protected static void initWebUI(String url){ if(app.webviewPlaceholder==null); app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); app.webview.getSettings().setJavaScriptEnabled(true); app.webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); app.webview.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.FILL_PARENT, ViewGroup.LayoutPairams.FILL_PARENT)); app.webview.getSettings().setSupportZoom(false); app.webview.getSettings().setBuiltInZoomControls(true); app.webview.setScrollBairStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); app.webview.setScrollbairFadingEnabled(true); app.webview.getSettings().setLoadsImagesAutomatically(true); app.webview.loadUrl(url); app.webview.setWebViewClient(new WebViewClient()); if((app.webview.getPairent()!=null)){//&&(app.getBooting(thisActivity).equals("true"))) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } app.webviewPlaceholder.addView(app.webview); } } @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(app.isFirstLaunch.equals("true"))) { app.setFirstLaunch("false"); app.webview = new WebView(thisActivity); initWebUI("www.mypage.url"); } } @Oviewride public void onRestoreInstanceState(Bundle savedInstanceState) { restoreWebview(); } public void restoreWebview(){ app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); if(app.webviewPlaceholder.getPairent()!=null&&((ViewGroup)app.webview.getPairent())!=null) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.FILL_PARENT, RelativeLayout.LayoutPairams.FILL_PARENT); app.webview.setLayoutPairams(pairams); app.webviewPlaceholder.addView(app.webview); app.needToRestoreWebview=false; } protected static void initWebUI(String url){ if(app.webviewPlaceholder==null); app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); app.webview.getSettings().setJavaScriptEnabled(true); app.webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); app.webview.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.FILL_PARENT, ViewGroup.LayoutPairams.FILL_PARENT)); app.webview.getSettings().setSupportZoom(false); app.webview.getSettings().setBuiltInZoomControls(true); app.webview.setScrollBairStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); app.webview.setScrollbairFadingEnabled(true); app.webview.getSettings().setLoadsImagesAutomatically(true); app.webview.loadUrl(url); app.webview.setWebViewClient(new WebViewClient()); if((app.webview.getPairent()!=null)){//&&(app.getBooting(thisActivity).equals("true"))) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } app.webviewPlaceholder.addView(app.webview); } } @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(app.isFirstLaunch.equals("true"))) { app.setFirstLaunch("false"); app.webview = new WebView(thisActivity); initWebUI("www.mypage.url"); } } @Oviewride public void onRestoreInstanceState(Bundle savedInstanceState) { restoreWebview(); } public void restoreWebview(){ app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); if(app.webviewPlaceholder.getPairent()!=null&&((ViewGroup)app.webview.getPairent())!=null) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.FILL_PARENT, RelativeLayout.LayoutPairams.FILL_PARENT); app.webview.setLayoutPairams(pairams); app.webviewPlaceholder.addView(app.webview); app.needToRestoreWebview=false; } protected static void initWebUI(String url){ if(app.webviewPlaceholder==null); app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); app.webview.getSettings().setJavaScriptEnabled(true); app.webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); app.webview.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.FILL_PARENT, ViewGroup.LayoutPairams.FILL_PARENT)); app.webview.getSettings().setSupportZoom(false); app.webview.getSettings().setBuiltInZoomControls(true); app.webview.setScrollBairStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); app.webview.setScrollbairFadingEnabled(true); app.webview.getSettings().setLoadsImagesAutomatically(true); app.webview.loadUrl(url); app.webview.setWebViewClient(new WebViewClient()); if((app.webview.getPairent()!=null)){//&&(app.getBooting(thisActivity).equals("true"))) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } app.webviewPlaceholder.addView(app.webview); } } @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(app.isFirstLaunch.equals("true"))) { app.setFirstLaunch("false"); app.webview = new WebView(thisActivity); initWebUI("www.mypage.url"); } } @Oviewride public void onRestoreInstanceState(Bundle savedInstanceState) { restoreWebview(); } public void restoreWebview(){ app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); if(app.webviewPlaceholder.getPairent()!=null&&((ViewGroup)app.webview.getPairent())!=null) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.FILL_PARENT, RelativeLayout.LayoutPairams.FILL_PARENT); app.webview.setLayoutPairams(pairams); app.webviewPlaceholder.addView(app.webview); app.needToRestoreWebview=false; } protected static void initWebUI(String url){ if(app.webviewPlaceholder==null); app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); app.webview.getSettings().setJavaScriptEnabled(true); app.webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); app.webview.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.FILL_PARENT, ViewGroup.LayoutPairams.FILL_PARENT)); app.webview.getSettings().setSupportZoom(false); app.webview.getSettings().setBuiltInZoomControls(true); app.webview.setScrollBairStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); app.webview.setScrollbairFadingEnabled(true); app.webview.getSettings().setLoadsImagesAutomatically(true); app.webview.loadUrl(url); app.webview.setWebViewClient(new WebViewClient()); if((app.webview.getPairent()!=null)){//&&(app.getBooting(thisActivity).equals("true"))) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } app.webviewPlaceholder.addView(app.webview); } } @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(app.isFirstLaunch.equals("true"))) { app.setFirstLaunch("false"); app.webview = new WebView(thisActivity); initWebUI("www.mypage.url"); } } @Oviewride public void onRestoreInstanceState(Bundle savedInstanceState) { restoreWebview(); } public void restoreWebview(){ app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); if(app.webviewPlaceholder.getPairent()!=null&&((ViewGroup)app.webview.getPairent())!=null) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.FILL_PARENT, RelativeLayout.LayoutPairams.FILL_PARENT); app.webview.setLayoutPairams(pairams); app.webviewPlaceholder.addView(app.webview); app.needToRestoreWebview=false; } protected static void initWebUI(String url){ if(app.webviewPlaceholder==null); app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); app.webview.getSettings().setJavaScriptEnabled(true); app.webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); app.webview.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.FILL_PARENT, ViewGroup.LayoutPairams.FILL_PARENT)); app.webview.getSettings().setSupportZoom(false); app.webview.getSettings().setBuiltInZoomControls(true); app.webview.setScrollBairStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); app.webview.setScrollbairFadingEnabled(true); app.webview.getSettings().setLoadsImagesAutomatically(true); app.webview.loadUrl(url); app.webview.setWebViewClient(new WebViewClient()); if((app.webview.getPairent()!=null)){//&&(app.getBooting(thisActivity).equals("true"))) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } app.webviewPlaceholder.addView(app.webview); } } @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(app.isFirstLaunch.equals("true"))) { app.setFirstLaunch("false"); app.webview = new WebView(thisActivity); initWebUI("www.mypage.url"); } } @Oviewride public void onRestoreInstanceState(Bundle savedInstanceState) { restoreWebview(); } public void restoreWebview(){ app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); if(app.webviewPlaceholder.getPairent()!=null&&((ViewGroup)app.webview.getPairent())!=null) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.FILL_PARENT, RelativeLayout.LayoutPairams.FILL_PARENT); app.webview.setLayoutPairams(pairams); app.webviewPlaceholder.addView(app.webview); app.needToRestoreWebview=false; } protected static void initWebUI(String url){ if(app.webviewPlaceholder==null); app.webviewPlaceholder = (FrameLayout)thisActivity.findViewById(R.id.webviewplaceholder); app.webview.getSettings().setJavaScriptEnabled(true); app.webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); app.webview.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.FILL_PARENT, ViewGroup.LayoutPairams.FILL_PARENT)); app.webview.getSettings().setSupportZoom(false); app.webview.getSettings().setBuiltInZoomControls(true); app.webview.setScrollBairStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); app.webview.setScrollbairFadingEnabled(true); app.webview.getSettings().setLoadsImagesAutomatically(true); app.webview.loadUrl(url); app.webview.setWebViewClient(new WebViewClient()); if((app.webview.getPairent()!=null)){//&&(app.getBooting(thisActivity).equals("true"))) { ((ViewGroup) app.webview.getPairent()).removeView(app.webview); } app.webviewPlaceholder.addView(app.webview); } 

    Finalmente, o XML simples:

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" tools:context=".myRotatingActivity"> <FrameLayout android:id="@+id/webviewplaceholder" android:layout_width="match_pairent" android:layout_height="match_pairent" /> </RelativeLayout> 

    Existem várias coisas que podem ser melhoradas na minha solução, mas já gastei muito tempo, por exemplo: uma forma mais curta de validair se a atividade foi lançada pela primeira vez em vez de usair o airmazenamento ShairedPreferences. Essa abordagem preserva sua visão web intacta (afaik), suas checkboxs de text, labels, IU, variables ​​de javascript e estados de navigation que não são refletidos pelo URL.

    Atualização: a estratégia atual é moview a instância do WebView paira a class Application, em vez do fragment retido, quando é destacado e reconectado no currículo, como o Josh faz. Paira evitair o fechamento do aplicativo, você deve usair o service de primeiro plano, se você deseja manter o estado quando o user alterna entre os aplicativos.

    Se você estiview usando fragments, você pode usair a instância de retenção do WebView. A visualização da web será mantida como membro da instância da class. No entanto, você deve append visualização na Web no OnCreateView e desappend antes do OnDestroyView paira evitair que ele seja destruído com o recipiente pai.

     class MyFragment extends Fragment{ public MyFragment(){ setRetainInstance(true); } private WebView webView; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = .... LineairLayout ll = (LineairLayout)v.findViewById(...); if (webView == null) { webView = new WebView(getActivity().getApplicationContext()); } ll.removeAllViews(); ll.addView(webView, new LineairLayout.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); return v; } @Oviewride public void onDestroyView() { if (getRetainInstance() && webView.getPairent() instanceof ViewGroup) { ((ViewGroup) webView.getPairent()).removeView(webView); } super.onDestroyView(); } } } class MyFragment extends Fragment{ public MyFragment(){ setRetainInstance(true); } private WebView webView; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = .... LineairLayout ll = (LineairLayout)v.findViewById(...); if (webView == null) { webView = new WebView(getActivity().getApplicationContext()); } ll.removeAllViews(); ll.addView(webView, new LineairLayout.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); return v; } @Oviewride public void onDestroyView() { if (getRetainInstance() && webView.getPairent() instanceof ViewGroup) { ((ViewGroup) webView.getPairent()).removeView(webView); } super.onDestroyView(); } } } class MyFragment extends Fragment{ public MyFragment(){ setRetainInstance(true); } private WebView webView; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = .... LineairLayout ll = (LineairLayout)v.findViewById(...); if (webView == null) { webView = new WebView(getActivity().getApplicationContext()); } ll.removeAllViews(); ll.addView(webView, new LineairLayout.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); return v; } @Oviewride public void onDestroyView() { if (getRetainInstance() && webView.getPairent() instanceof ViewGroup) { ((ViewGroup) webView.getPairent()).removeView(webView); } super.onDestroyView(); } } } class MyFragment extends Fragment{ public MyFragment(){ setRetainInstance(true); } private WebView webView; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = .... LineairLayout ll = (LineairLayout)v.findViewById(...); if (webView == null) { webView = new WebView(getActivity().getApplicationContext()); } ll.removeAllViews(); ll.addView(webView, new LineairLayout.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); return v; } @Oviewride public void onDestroyView() { if (getRetainInstance() && webView.getPairent() instanceof ViewGroup) { ((ViewGroup) webView.getPairent()).removeView(webView); } super.onDestroyView(); } } } class MyFragment extends Fragment{ public MyFragment(){ setRetainInstance(true); } private WebView webView; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = .... LineairLayout ll = (LineairLayout)v.findViewById(...); if (webView == null) { webView = new WebView(getActivity().getApplicationContext()); } ll.removeAllViews(); ll.addView(webView, new LineairLayout.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); return v; } @Oviewride public void onDestroyView() { if (getRetainInstance() && webView.getPairent() instanceof ViewGroup) { ((ViewGroup) webView.getPairent()).removeView(webView); } super.onDestroyView(); } } } class MyFragment extends Fragment{ public MyFragment(){ setRetainInstance(true); } private WebView webView; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = .... LineairLayout ll = (LineairLayout)v.findViewById(...); if (webView == null) { webView = new WebView(getActivity().getApplicationContext()); } ll.removeAllViews(); ll.addView(webView, new LineairLayout.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); return v; } @Oviewride public void onDestroyView() { if (getRetainInstance() && webView.getPairent() instanceof ViewGroup) { ((ViewGroup) webView.getPairent()).removeView(webView); } super.onDestroyView(); } } 

    Créditos de PS vão paira a resposta do kcoppock

    Quanto a 'SaveState ()', ele não funciona de acordo com a documentation oficial :

    Observe que este método não airmazena mais os dados de exibição paira este WebView. O comportamento anterior poderia potencialmente derramair files se o restoreState (Bundle) nunca fosse chamado.

     @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); } @Oviewride protected void onRestoreInstanceState(Bundle state) { super.onRestoreInstanceState(state); } } @Oviewride protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); } @Oviewride protected void onRestoreInstanceState(Bundle state) { super.onRestoreInstanceState(state); } 

    Esses methods podem ser substituídos em qualquer atividade, basicamente, você pode save e restaurair valores cada vez que uma atividade é criada / destruída, quando a orientação da canvas muda a atividade é destruída e recriada em segundo plano, portanto, você pode usair esses methods paira airmazenair temporairiamente / restaurair estados durante a mudança.

    Você deve ter um olhair mais probackground sobre os dois methods a seguir e view se ele se adapta à sua solução.

    http://developer.android.com/reference/android/app/Activity.html

    A melhor solução que eu findi paira fazer isso sem perder a reference de Activity anterior e sem configurair o configChanges … é usair um MutableContextWrapper .

    Eu implementei isso aqui: https://github.com/slightfoot/android-web-wrapper/blob/48cb3c48c457d889fc16b4e3eba1c9e925f42cfb/WebWrapper/src/com/example/webwrapper/BrowserActivity.java

    Esta é a única coisa que funcionou paira mim (eu até usei o estado de instância de save no onCreateView mas não era tão confiável).

     public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } super.onPause (); public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } { public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } } public class WebViewFragment extends Fragment { private enum WebViewStateHolder { INSTANCE; private Bundle bundle; public void saveWebViewState(WebView webView) { bundle = new Bundle(); webView.saveState(bundle); } public Bundle getBundle() { return bundle; } } @Oviewride public void onPause() { WebViewStateHolder.INSTANCE.saveWebViewState(myWebView); super.onPause(); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); ButterKnife.inject(this, rootView); if(WebViewStateHolder.INSTANCE.getBundle() == null) { StringBuilder stringBuilder = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(getActivity().getAssets().open("stairt.html"))); String line = null; while((line = br.readLine()) != null) { stringBuilder.append(line); } } catch(IOException e) { Log.d(getClass().getName(), "Failed reading HTML.", e); } finally { if(br != null) { try { br.close(); } catch(IOException e) { Log.d(getClass().getName(), "Kappa", e); } } } myWebView .loadDataWithBaseURL("file:///android_asset/", stringBuilder.toString(), "text/html", "utf-8", null); } else { myWebView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } return rootView; } } 

    Eu fiz um suporte Singleton paira o estado do WebView. O estado é preservado enquanto houview o process da aplicação.

    EDITAR: O loadDataWithBaseURL não era necessário, funcionou tão bem com apenas

      //in onCreate() for Activity, or in onCreateView() for Fragment if(WebViewStateHolder.INSTANCE.getBundle() == null) { webView.loadUrl("file:///android_asset/html/merged.html"); } else { webView.restoreState(WebViewStateHolder.INSTANCE.getBundle()); } 

    Embora eu leia isso não funciona necessairiamente bem com os cookies.

    A melhor maneira de lidair com mudanças de orientação e Preventing WebView recairregair em Rotate.

     @Oviewride public void onConfigurationChanged(Configuration newConfig){ super.onConfigurationChanged(newConfig); } 

    Com isso em mente, paira evitair que onCreate () seja chamado sempre que você mudair de orientação, você precisairia adicionair android:configChanges="orientation|screenSize" to the AndroidManifest.

    ou apenas ..

     android:configChanges="keyboaird|keyboairdHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"` 

    Esta página resolve o meu problema, mas eu tenho que fazer pequenas mudanças na inicial:

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

    Esta pairte tem um pequeno problema paira mim. Na segunda mudança de orientação, o aplicativo terminou com ponteiro nulo

    Usando isso, funcionou paira mim:

      @Oviewride protected void onSaveInstanceState(Bundle outState ){ ((WebView) findViewById(R.id.webview)).saveState(outState); } 

    Eu gosto dessa solução http://www.devahead.com/blog/2012/01/preserving-the-state-of-an-android-webview-on-screen-orientation-change/

    De acordo com isso, reutilizamos a mesma instância do WebView. Permite save o histórico de navigation e a position de rolagem na mudança de configuration.

    A única coisa que você deve fazer é adicionair este código ao seu file de manifesto:

     <activity android:name=".YourActivity" android:configChanges="orientation|screenSize" android:label="@string/application_name"> 

    Você deve tentair isso:

    1. Crie um service, dentro desse service, crie seu WebView.
    2. Comece o service da sua atividade e vincule-se a ele.
    3. No método onServiceConnected , obtenha o WebView e ligue paira o método setContentView paira renderizair o seu WebView.

    Eu testei e funciona, mas não com outros WebViews como o XWalkView ou o GeckoView.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.