android - how to use runOnUiThread without getting "cannot make a static reference to the non static method" compiler error -
android - how to use runOnUiThread without getting "cannot make a static reference to the non static method" compiler error -
i have main class;
clientplayer extends activity {
and service
lotteryserver extends service implements runnable {
when trying utilize runonuithread in run method of service getting compiler error of, "cannot create static reference non static method"
how prepare this?, how using code shown here;
@override public void run() { // tried both clientplayer.runonuithread , lotteryserver.runonuithread // both don't work clientplayer.runonuithread(new runnable() { public void run() { toast.maketext(getapplicationcontext(), "from within thread", toast.length_short).show(); } }); } // end run method
runonuithread not static method.
if u want run runnable on uithread can utilize this
handler handler = new handler(looper.getmainlooper());
this create handler ui thread.
clientplayer extends activity { . . public static handler uihandler; static { uihandler = new handler(looper.getmainlooper()); } public static void runonui(runnable runnable) { uihandler.post(runnable); } . . . }
now u can utilize anywhere.
@override public void run() { // tried both clientplayer.runonuithread , lotteryserver.runonuithread // both don't work clientplayer.runonui(new runnable() { public void run() { toast.maketext(getapplicationcontext(), "from within thread", toast.length_short).show(); } }); } // end run method
android multithreading
Comments
Post a Comment