Last active
August 29, 2015 14:06
-
-
Save g-1/d6b34a8b495901202b93 to your computer and use it in GitHub Desktop.
cocos2d-xのtouchイベント内でtoastを表示したいとき。 ref: http://qiita.com/g-1/items/0323cd56a53029f1fa65
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//jni経由でコールされるメソッド | |
Handler handler = new Handler(Looper.getMainLooper()); | |
handler.post(new Runnable(){ | |
public void run(){ | |
Toast toast = new Toast(… | |
… | |
toast.show(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Handler(Callback callback, boolean async) { | |
if (FIND_POTENTIAL_LEAKS) { | |
final Class<? extends Handler> klass = getClass(); | |
if ((klass.isAnonymousClass() || klass.isMemberClass() || klass.isLocalClass()) && | |
(klass.getModifiers() & Modifier.STATIC) == 0) { | |
Log.w(TAG, "The following Handler class should be static or leaks might occur: " + | |
klass.getCanonicalName()); | |
} | |
} | |
mLooper = Looper.myLooper(); | |
if (mLooper == null) { | |
throw new RuntimeException( | |
"Can't create handler inside thread that has not called Looper.prepare()"); | |
} | |
mQueue = mLooper.mQueue; | |
mCallback = callback; | |
mAsynchronous = async; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment