java - `Can't create handler...Looper.prepare()` in inherited Activity -
java - `Can't create handler...Looper.prepare()` in inherited Activity -
i have game activity (activity a) works code. create new activity (activity b) new game mode, extends activity a. however, when encounter toast line, activity b thrown exception (activity works showing toast):
can't create handler within thread has not called looper.prepare()
activity b overrides load-level method, no differrence!
try this:
handler innerhandler; (new thread(new runnable() { @override public void run() { looper.prepare(); innerhandler = new handler() { @override public void handlemessage(message message) { toast.make(...); } @override public void dispatchmessage(message message) { handlemessage(message); } }; message message = innerhandler.obtainmessage(); innerhandler.dispatchmessage(message); looper.loop(); } })).start(); there may easier way handle problem. please refer android – multithreading in ui environment documentation.
java android handler toast looper
Comments
Post a Comment