Created
August 21, 2014 07:25
-
-
Save wicksome/4183bc4821c00634f310 to your computer and use it in GitHub Desktop.
handler_1
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 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.sendEmptyMessage(0); | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
// 스레드간의 통신장치 | |
public Handler mHandler = new Handler() { | |
public void handleMessage(Message msg) { | |
if (msg.what == 0) { | |
tvTest.setText(val + ""); | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment