android twitter login Looper.prepair -
i'm making login android application using twitter api dialog contains web view component
this error come logcat "can't create handler inside thread has not looper.prepare() " solution of error ? code of oauthrequesttokentask.java class
import com.noqwerty.m.loginactivity; import oauth.signpost.oauthconsumer; import oauth.signpost.oauthprovider; import android.content.context; import android.os.asynctask; import android.os.looper; import android.util.log; public class oauthrequesttokentask extends asynctask<void, void, void> { final string tag = getclass().getname(); private context context; private oauthprovider provider; private oauthconsumer consumer; public oauthrequesttokentask(context context, oauthconsumer consumer, oauthprovider provider) { this.context = context; this.consumer = consumer; this.provider = provider; } @override protected void doinbackground(void... params) { try { log.i(tag, "retrieving request token google servers"); final string url = provider.retrieverequesttoken(consumer, constants.oauth_callback_url); log.i(tag, "popping browser authorize url : " + url); // intent intent = new intent(intent.actution_view, // uri.parse(url)).setflags(intent.flag_activity_single_top | // intent.flag_activity_no_history | intent.flag_from_background); // context.startactivity(intent); // looper.prepare(); loginactivity.twd.setupwebview(url); } catch (exception e) { log.e(tag, "error during oauth retrieve request token", e); } return null; } }
this twitterdialog.java class
import oauth.signpost.oauthconsumer; import oauth.signpost.oauthprovider; import oauth.signpost.commonshttp.commonshttpoauthconsumer; import oauth.signpost.commonshttp.commonshttpoauthprovider; import oauth.signpost.http.httpparameters; import android.app.dialog; import android.app.progressdialog; import android.content.context; import android.graphics.bitmap; import android.graphics.color; import android.graphics.typeface; import android.graphics.drawable.drawable; import android.os.bundle; import android.util.log; import android.view.display; import android.view.viewgroup; import android.view.window; import android.webkit.webview; import android.webkit.webviewclient; import android.widget.framelayout; import android.widget.linearlayout; import android.widget.textview; public class twitterdialog extends dialog { static final float[] dimensions_landscape = { 460, 260 }; static final float[] dimensions_portrait = { 280, 420 }; static final framelayout.layoutparams fill = new framelayout.layoutparams( viewgroup.layoutparams.fill_parent, viewgroup.layoutparams.fill_parent); static final int margin = 4; static final int padding = 2; private progressdialog mspinner; private webview mwebview; private linearlayout mcontent; private textview mtitle; private boolean progressdialogrunning = false; final string tag = getclass().getname(); private oauthconsumer consumer; private oauthprovider provider; httpparameters params1; public twitterdialog(context context) { super(context); try { this.consumer = new commonshttpoauthconsumer( constants.consumer_key, constants.consumer_secret); this.provider = new commonshttpoauthprovider(constants.request_url, constants.access_url, constants.authorize_url); } catch (exception e) { log.e(tag, "error creating consumer / provider", e); } log.i(tag, "starting task retrieve request token."); new oauthrequesttokentask(this.getcontext(), consumer, provider) .execute(); } // @override // protected void oncreate(bundle savedinstancestate) { // super.oncreate(savedinstancestate); // try { // this.consumer = new commonshttpoauthconsumer( // constants.consumer_key, constants.consumer_secret); // this.provider = new commonshttpoauthprovider(constants.request_url, // constants.access_url, constants.authorize_url); // } catch (exception e) { // log.e(tag, "error creating consumer / provider", e); // } // // log.i(tag, "starting task retrieve request token."); // new oauthrequesttokentask(this.getcontext(), consumer, provider).execute(); // // } private void setuptitle() { requestwindowfeature(window.feature_no_title); mtitle = new textview(getcontext()); mtitle.settext("twitter"); mtitle.settextcolor(color.white); mtitle.settypeface(typeface.default_bold); mtitle.setbackgroundcolor(0xffbbd7e9); mtitle.setpadding(margin + padding, margin, margin, margin); mtitle.setcompounddrawablepadding(margin + padding); mcontent.addview(mtitle); } public void setupwebview(string u) { mwebview = new webview(getcontext()); mwebview.setverticalscrollbarenabled(false); mwebview.sethorizontalscrollbarenabled(false); mwebview.loadurl(u); mwebview.setwebviewclient(new twitterwebviewclient()); mwebview.getsettings().setjavascriptenabled(true); mwebview.setlayoutparams(fill); mcontent.addview(mwebview); } private class twitterwebviewclient extends webviewclient { @override public boolean shouldoverrideurlloading(webview view, string url) { view.loadurl(url); return true; } @override public void onreceivederror(webview view, int errorcode, string description, string failingurl) { super.onreceivederror(view, errorcode, description, failingurl); /// mlistener.onerror(description); twitterdialog.this.dismiss(); } @override public void onpagestarted(webview view, string url, bitmap favicon) { super.onpagestarted(view, url, favicon); mspinner.show(); progressdialogrunning = true; } @override public void onpagefinished(webview view, string url) { super.onpagefinished(view, url); string title = mwebview.gettitle(); if (title != null && title.length() > 0) { mtitle.settext(title); } progressdialogrunning = false; mspinner.dismiss(); } } @override protected void onstop() { progressdialogrunning = false; super.onstop(); } public void onbackpressed() { if(!progressdialogrunning){ twitterdialog.this.dismiss(); } } }
the logcat output
05-02 12:47:17.517: e/com.noqwerty.m.twitter.oauthrequesttokentask(1703): error during oauth retrieve request token 05-02 12:47:17.517: e/com.noqwerty.m.twitter.oauthrequesttokentask(1703): java.lang.runtimeexception: can't create handler inside thread has not called looper.prepare() 05-02 12:47:17.517: e/com.noqwerty.m.twitter.oauthrequesttokentask(1703): @ android.os.handler.<init>(handler.java:197) 05-02 12:47:17.517: e/com.noqwerty.m.twitter.oauthrequesttokentask(1703): @ android.os.handler.<init>(handler.java:111) 05-02 12:47:17.517: e/com.noqwerty.m.twitter.oauthrequesttokentask(1703): @ android.webkit.webviewclassic$privatehandler.<init>(webviewclassic.java:7242)
it seems of methods tries access ui background thread , fails. move ui logic onpostexecute processed on ui thread.
Comments
Post a Comment