Home > Android > Handler in android

Handler in android


In this tutorial I will tell you how to use handler to switch between to activity, I will create two classes and name it FirstActivity.class, SecondActivity.
Content in two file depend on you, you can add button or  textview into these classes. In here I will add Handler into FirstActivity, when I start FirstActivity.class and waiting for 2 second, Activity will automatically change to SencondActivity.class. Code here:

public class ReceiveActivity extends Activity{
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.main);
Handler handler = new Handler();
handler.postDelayed(new waitforhandle(), 2000);

}

public class waitforhandle implements Runnable{
public void run() {
Intent t = new Intent(getApplicationContext(),SecondActivity.class);
startActivity(t);
finish();
}
}
}

Categories: Android
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: