Android: avoid webview refresh in tab fragment -


i'm creating app 2 tabs, 1 of tabs contains webview. problem every time switch between tabs, webview refreshed.

my structure is:

i created actionbar , tabs extends fragment

my tab2 class code:

public class copyoftab2 extends fragment implements actionbar.tablistener{      private fragment mfragment;     private webview mwebview ;     private bundle webviewbundle;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          getactivity().setcontentview(r.layout.activity_tab2);     }      public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         log.e("rh", "in oncreateview");         view v = inflater.inflate(r.layout.activity_tab2, container, false);         //imageview imageview = (imageview)v.findviewbyid(r.id.my_image);         return v;     }         @override     public void onviewcreated(view view, bundle savedinstancestate) {          mwebview = (webview)view.findviewbyid(r.id.gallerywebview);         //gallery.setadapter(adapter);          mwebview.getsettings().setjavascriptenabled(true); // enable javascript              mwebview.setwebviewclient(new webviewclient() {                 public void onreceivederror(webview view, int errorcode, string description, string failingurl) {                     log.e("rh","error in web rh");                     //toast.maketext(activity, description, toast.length_short).show();                 }             });              if (webviewbundle == null) {                 log.e("rh","webviewbundle null");                 mwebview.loadurl("http://www.google.com");                   }              else {                 log.e("rh","webviewbundle not null");                 mwebview.restorestate(webviewbundle);                            }          super.onviewcreated(view, savedinstancestate);     }      public void ontabselected(tab tab, fragmenttransaction ft) {          //switchcontent("tab2");              // todo auto-generated method stub             mfragment = new copyoftab2();             // attach fragment1.xml layout             ft.add(android.r.id.content, mfragment);             ft.attach(mfragment);      }      public void ontabunselected(tab tab, fragmenttransaction ft) {         // todo auto-generated method stub         // remove fragment1.xml layout         //ft.remove(mfragment);         ft.hide(mfragment);     }      public void ontabreselected(tab tab, fragmenttransaction ft) {         // todo auto-generated method stub     } } 

i using similar approach , suffering same problem, because every time tab selected new instance of fragment created:

mfragment = new copyoftab2(); 

hence executed again.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -