Skip to content

Instantly share code, notes, and snippets.

@wicksome
Last active August 29, 2015 14:05
Show Gist options
  • Save wicksome/72030b427e852b50efb5 to your computer and use it in GitHub Desktop.
Save wicksome/72030b427e852b50efb5 to your computer and use it in GitHub Desktop.
더 간단한 코드
public class ThreadHandlerTest extends Activity {
TextView tvTest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
tvTest = (TextView) findViewById(R.id.tv_test);
BackThread thread = new BackThread();
thread.setDaemon(true); // 메인스레드와 같이 종료하기 위해서
thread.start();
}
class BackThread extends Thread {
@Override
public void run() {
val++;
mHandler.post(new Runnable() {
public void run() {
tvTest.setText(val + "");
}
});
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Handler mHandler = new Handler();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment