2014/04/12

How do you pause in android (Java)?

First you have to create a Handler();, then you have to use the postDelayed function to pause the code.

public class MyActivity extends Activity {
    private Handler mHandler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHandler.postDelayed(new Runnable() {
            public void run() {
                doStuff();
            }
        }, 5000);
    }

    private void doStuff() {
        System.out.println("Hellow World After 5 seconds!");
    }
}

No comments:

Post a Comment