Skip to content

Instantly share code, notes, and snippets.

@g-1
Last active August 29, 2015 14:06
Show Gist options
  • Save g-1/d6b34a8b495901202b93 to your computer and use it in GitHub Desktop.
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
//jni経由でコールされるメソッド
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable(){
public void run(){
Toast toast = new Toast(…
toast.show();
}
});
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