Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Created January 16, 2014 06:27
Show Gist options
  • Save benigumocom/8450654 to your computer and use it in GitHub Desktop.
Save benigumocom/8450654 to your computer and use it in GitHub Desktop.
Threadによる非同期処理
final Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
switch(msg.what) {
case RESULT_WHAT:
handleResult((Result) msg.obj);
return true;
}
return false;
}
});
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Result result = doStuff();
if (isResumed()) {
handler.sendMessage(handler.obtainMessage(RESULT_WHAT, result));
}
}
});
thread.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment