Guest User

Untitled

a guest
Nov 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. private Bundle webViewBundle;
  2.  
  3. public void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. ...
  6. setRetainInstance(true);
  7. ...
  8. }
  9.  
  10. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  11. Bundle savedInstanceState) {
  12.  
  13. View v = inflater.inflate(R.layout.my_layout, container, false);
  14. wv = (WebView) v.findViewById(R.id.webView);
  15.  
  16. if (webViewBundle != null)
  17. {
  18. wv.restoreState(webViewBundle);
  19. }
  20. else
  21. {
  22. wv.loadUrl("http://www.mysite.mydomain");
  23. }
  24.  
  25. return v;
  26. }
  27.  
  28. public void onPause() {
  29. super.onPause();
  30. webViewBundle = new Bundle();
  31. wv.saveState(webViewBundle);
  32. }
  33.  
  34. <activity
  35. ...
  36. android:configChanges="orientation|screenSize"
  37. ... ></activity>
  38.  
  39. public void onCreate(Bundle savedInstanceState) {
  40. super.onCreate(savedInstanceState);
  41. setRetainInstance(true);
  42. }
  43.  
  44.  
  45. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  46. Bundle savedInstanceState) {
  47.  
  48. View v = inflater.inflate(R.layout.webview_layout, container, false);
  49. wv = v.findViewById(R.id.web_view);
  50.  
  51. WebSettings webSettings = wv.getSettings();
  52. webSettings.setJavaScriptEnabled(true);
  53.  
  54. wv.setWebViewClient(new WebViewClient());
  55. wv.loadUrl("https://www.carngo.com/");
  56.  
  57. return v;
  58. }
Add Comment
Please, Sign In to add comment