Scribe-java and async request in Android 4 -


in android 4.2.2 emulator try use scribe code snippet:

oauthservice service = new servicebuilder()             .provider(twitterapi.class)             .apikey("abc")             .apisecret("aaa123")             .debug()             .build();     scanner in = new scanner(system.in);     token requesttoken = service.getrequesttoken(); 

in logcat following error. think can because of scribe's example code not async-task. can recommend async example please ?

note code snippet works in android 2.3.3. doesn't work in android 4.2.2.

    e/androidruntime: fatal exception: main     java.lang.runtimeexception:        unable start activity         componentinfo{com.myexample.android/com.myexample.android.myactivity}:        org.scribe.exceptions.oauthconnectionexception:       there problem while creating connection remote service.     @ android.app.activitythread.performlaunchactivity(activitythread.java:2180)     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230)     @ android.app.activitythread.access$600(activitythread.java:141)     @ android.app.activitythread$h.handlemessage(activitythread.java:1234)     @ android.os.handler.dispatchmessage(handler.java:99)     @ android.os.looper.loop(looper.java:137)     @ android.app.activitythread.main(activitythread.java:5039)     @ java.lang.reflect.method.invokenative(native method)     @ java.lang.reflect.method.invoke(method.java:511)     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793)     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560)     @ dalvik.system.nativestart.main(native method)     caused by: org.scribe.exceptions.oauthconnectionexception: there problem while creating connection remote service.     @ org.scribe.model.request.send(request.java:70)     @ org.scribe.oauth.oauth10aserviceimpl.getrequesttoken(oauth10aserviceimpl.java:59)     @ org.scribe.oauth.oauth10aserviceimpl.getrequesttoken(oauth10aserviceimpl.java:40)     @ org.scribe.oauth.oauth10aserviceimpl.getrequesttoken(oauth10aserviceimpl.java:45)     @ com.myexample.android.myactivity.oncreate(myactivity.java:139)     @ android.app.activity.performcreate(activity.java:5104)     @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080)     @ android.app.activitythread.performlaunchactivity(activitythread.java:2144)     ... 11 more     caused by: android.os.networkonmainthreadexception     @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1117)     @ java.net.inetaddress.lookuphostbyname(inetaddress.java:385)     @ java.net.inetaddress.getallbynameimpl(inetaddress.java:236)     @ java.net.inetaddress.getallbyname(inetaddress.java:214)     @ libcore.net.http.httpconnection.<init>(httpconnection.java:70)     @ libcore.net.http.httpconnection.<init>(httpconnection.java:50)     @ libcore.net.http.httpconnection$address.connect(httpconnection.java:340)     @ libcore.net.http.httpconnectionpool.get(httpconnectionpool.java:87)     @ libcore.net.http.httpconnection.connect(httpconnection.java:128)     @ libcore.net.http.httpengine.opensocketconnection(httpengine.java:316)     @ libcore.net.http.httpengine.connect(httpengine.java:311)     @ libcore.net.http.httpengine.sendsocketrequest(httpengine.java:290)     @ libcore.net.http.httpengine.sendrequest(httpengine.java:240)     @ libcore.net.http.httpurlconnectionimpl.connect(httpurlconnectionimpl.java:81)     @ libcore.net.http.httpurlconnectionimpl.getoutputstream(httpurlconnectionimpl.java:197)     @ org.scribe.model.request.addbody(request.java:136)     @ org.scribe.model.request.dosend(request.java:114)     @ org.scribe.model.request.send(request.java:66)     ... 18 more 

this because later versions of android require network connections happen off of main thread. used asynctask this, being depracated in future version of android.

i suggest using asynctaskloader if need receive result , update ui. otherwise, can use intentservice (or other service type). can create new thread directly. whatever decide, once move connection off of main thread won't receive networkonmainthreadexception more!


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -