I have a small Android application that automatically clicks the button after 5 seconds. I have used performClick();
but this does not work. When the timer gets to zero it simply crashes.
Here is my code:
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.local);
getActionBar().setIcon(R.drawable.menu_drop);
buttonClick();
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
button1.performClick();
}
}
};
timer.start();
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void buttonClick() {
button1 = (Button) findViewById(R.id.button);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(TestButton2.this, LocationView.class);
startActivity(i);
}
});
}