Android WebView Client Causes ANR -


i implementing client end library oauth api. in authentication process, webview client fire , load authentication page's url.however, webview client start correctly, started causing anrs.

here's code library:

public string inflateview(activity activity,string redirecturl, string scope){      final string rurl=redirecturl;     layoutinflater inflater = activity.getlayoutinflater();     page=inflater.inflate(r.layout.web_overlay, null);     final string scopes=scope;     activity.setcontentview(page);     gwebview = (webview) page.findviewbyid(r.id.webview);     gwebview.loadurl("https://api.23andme.com/authorize/?redirect_uri="             + redirecturl + "&response_type=code&client_id=" + this.clientid             + "&scope=" + scope );     log.d(tag, "http://192.241.244.189/auth/authorize?response_type=code&client_id=iv9amqp9&scope=read:sequence read:patient");      gwebview.setwebviewclient(new webviewclient(){         @override         public void onpagefinished(webview view, string url) {             super.onpagefinished(view, url);             if(url.startswith("https://api.23andme.com")){                 log.d(tag, "got authentication page");             }             if (url.startswith(rurl)) {                 system.out.println("got override");                 if (url.indexof("code=") != -1) {                     //if query contains code                     string querystring = null;                     try {                         querystring = new url(url).getquery();                     } catch (malformedurlexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                     }                     system.out.println(querystring);                     string[] params = querystring.split("&");                     (string param : params) {                         if (param.startswith("code=")) {                             code = param.substring(param.indexof('=') + 1);                         }                     }                     gwebview.setvisibility(view.gone);                     request= new postrequest();                     request.execute(code, smartclient.this.clientid, smartclient.this.clientsecret, rurl, scopes);                     log.d(tag, "post execute");                     log.d(tag, "cancelled");                     while(true){                         if(!accesstoken.equals("")){                             request.cancel(true);                             log.d(tag, "not empty");                             gwebview.destroy();                             break;                         }                     }                     // don't go redirecturi                 }             }         }     }); 

and called using:

client= new smartclient(id, secret);     string token=client.inflateview(smartactivity.this,redirect_uri, scope); 

the layout webview:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >  <webview     android:id="@+id/webview"     android:layout_width="match_parent"     android:layout_height="match_parent" />  </linearlayout> 

have unknowingly done stupid here?

edit: postrequest asynctask class, clarify. edit: found reason code running outside webview client:

    while(true){         if(!accesstoken.equals("")){             log.d(tag, "not empty");             break;         }     } 

it's not smart thing know, how implement listener mechanism waits until accesstoken not empty , returns it?

       while(true){                 if(!accesstoken.equals("")){                     request.cancel(true);                     log.d(tag, "not empty");                     gwebview.destroy();                     break;                 }             } 

you have loop, waits response background thread. it's not correct solution. consider using listener mechanism.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -