Created
January 16, 2014 06:27
-
-
Save benigumocom/8450654 to your computer and use it in GitHub Desktop.
Threadによる非同期処理
This file contains hidden or 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
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