my app executes asynctask when checkbox clicked. cant log message more once. on first click not again. after looking around @ other questions determined had build custom class , of course call new myaysnctask (which doing) still not working.
here code executes when checkbox clicked.
cbjoining.setonclicklistener(new onclicklistener() { public void onclick(view v) { new myasynctask(eventid, cbjoining.ischecked(), url_race, sdates, sstate ).execute(); } });
here custom class
class myasynctask extends asynctask<void, void, void>{ public string eventid; public boolean bjoin; public string url_race; public string sdates; public string sstate; public myasynctask( string myeventid, boolean mybjoin, string myurl_race, string mysdates, string mysstate){ super(); eventid = myeventid; bjoin = mybjoin; url_race = myurl_race; sdates = mysdates; sstate = mysstate; } protected void onpreexecute() { }; @override protected void doinbackground(void... args) { //looper.prepare(); api oapi = new api(); oapi.join(mprefs, eventid, bjoin, url_race, sdates, sstate); log.d("asynctask", url_race); //looper.loop(); return null; } protected void onpostexecute(void result) { log.d("asynctask", "finished"); }; }
here exception: 07-16 12:45:10.286: e/androidruntime(28309): fatal exception: asynctask #2
07-16 12:45:10.286: e/androidruntime(28309): java.lang.runtimeexception: error occured while executing doinbackground()
07-16 12:45:10.286: e/androidruntime(28309): @ android.os.asynctask$3.done(asynctask.java:299)
07-16 12:45:10.286: e/androidruntime(28309): @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:352)
07-16 12:45:10.286: e/androidruntime(28309): @ java.util.concurrent.futuretask.setexception(futuretask.java:219)
07-16 12:45:10.286: e/androidruntime(28309): @ java.util.concurrent.futuretask.run(futuretask.java:239)
07-16 12:45:10.286: e/androidruntime(28309): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230)
07-16 12:45:10.286: e/androidruntime(28309): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080)
07-16 12:45:10.286: e/androidruntime(28309): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573)
07-16 12:45:10.286: e/androidruntime(28309): @ java.lang.thread.run(thread.java:856)
07-16 12:45:10.286: e/androidruntime(28309): caused by: java.lang.runtimeexception: can't create handler inside thread has not called looper.prepare()
07-16 12:45:10.286: e/androidruntime(28309): @ android.os.handler.(handler.java:197)
07-16 12:45:10.286: e/androidruntime(28309): @ android.os.handler.(handler.java:111)
07-16 12:45:10.286: e/androidruntime(28309): @ android.app.activity.(activity.java:759)
07-16 12:45:10.286: e/androidruntime(28309): @ com.chartermatrixllc.motocrossmatrix.api$fb.(api.java:88)
07-16 12:45:10.286: e/androidruntime(28309): @ com.chartermatrixllc.motocrossmatrix.api.join(api.java:125)
07-16 12:45:10.286: e/androidruntime(28309): @ com.chartermatrixllc.motocrossmatrix.race$myasynctask.doinbackground(race.java:207)
07-16 12:45:10.286: e/androidruntime(28309): @ com.chartermatrixllc.motocrossmatrix.race$myasynctask.doinbackground(race.java:1)
07-16 12:45:10.286: e/androidruntime(28309): @ android.os.asynctask$2.call(asynctask.java:287)
07-16 12:45:10.286: e/androidruntime(28309): @ java.util.concurrent.futuretask.run(futuretask.java:234)
07-16 12:45:10.286: e/androidruntime(28309): ... 4 more
you working on android 4+, version asynctask
has 1 thread , blocked
looper.prepare(); log.d("asynctask", "clicked"); looper.loop();
so have several options:
1) use method asynctask.executeonexecutor
, provide own executor number of threads, example executors.newcachedthreadpool()
2) stop blocking asynctask
thread
Comments
Post a Comment