public class MainActivity extends AppCompatActivity {
Timer timer = new Timer();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
setTitle("hear me?");
Toast.makeText(MainActivity.this,"wo shi handler",Toast.LENGTH_SHORT).show();
break;
}
super.handleMessage(msg);
}
};
TimerTask task = new TimerTask(){
public void run() {
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
}
};
timer.schedule(task, 10000);
};
}