android - webview, using loadData at onResume loses history -


i have app reads articles in webview. when articleactivity first started, html of webpage downloaded string , parsed make mobile site, use wb.loaddata(html, "text/html; charset=utf-8", null);. downloading occurs in asynctask since can't internet activity on ui thread, now, whenever link on page clicked, defaults loadurl() per webviewclient. can use goback() in history this, no problem.

the problem lies search bar widget. call searchresultsactivity, opens webview , loads url. when user clicks on article, searchresultsactivity sends articleactivity through intent. problem want use loaddata() new article link, , try in onresume(), nothing happens if i'm still on loaded page. log statement shows url extra_return_result did make it, think intent good. think due javascript "same origin" thing, that's why if use loaddatawithbaseurl(), page loads. if try button now, loaded page blank! do preserve history when load new page?

class searchwebviewclient extends webviewclient {     @override     public boolean shouldoverrideurlloading(webview view, string url) {         // if morning sign out , article, send url articleactivity         if(uri.parse(url).gethost().endswith("morningsignout.com")) {             intent intent = new intent(view.getcontext(), articleactivity.class);             intent.putextra(intent.extra_return_result, url); // put url in intent             intent.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top); // open w/ old articleactivity if exists             view.getcontext().startactivity(intent);             return true;         }  //        intent intent = new intent(intent.action_view, uri.parse(url)); //        view.getcontext().startactivity(intent);         return false;     } } 

from articleactivity

@override protected void onresume() {     super.onresume();      // url categoryactivity     string intenturl = getintent().getstringextra(intent.extra_html_text);      // set webview new article     if (intenturl != null) new urltomobilearticle(webview).execute(intenturl);     else {         // if statement reached, intent originated searchresultsactivity         intenturl = getintent().getstringextra(intent.extra_return_result);         new urltomobilearticle(webview).execute(intenturl);         log.d("articleactivity", "loading: " + intenturl);     } } 

what urltomobilearticle is, getarticles() download/parsing function:

public urltomobilearticle(webview webview) {     this.wb = webview; }  @override protected string doinbackground(string... params) {     return getarticle(params[0]); }  @override protected void onpostexecute(final string html) {     wb.loaddata(html, "text/html; charset=utf-8", null);     // wb.loaddatawithbaseurl(link, html, "text/html; charset=utf-8", null, null);     log.d("urltomobilearticle", "loaded webpage"); } 

the answer can use shouldinterceptrequest() load html in way see fit. need ensure can distinguish between webpage urls , other requests images or style sheets


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -