1new java.util.Timer().schedule(
2 new java.util.TimerTask() {
3 @Override
4 public void run() {
5 // your code here
6 }
7 },
8 5000
9);
1Runnable mToastRunnable;
2Handler mHandler = new Handler();
3
4
5
6 //create runnable for delay
7 mToastRunnable = new Runnable() {
8 @Override
9 public void run() {
10 Toast.makeText(MainActivity.this, "This is a delayed toast", Toast.LENGTH_SHORT).show();
11 mHandler.postDelayed(this, 3000000);
12 getlocation();
13 }
14 };
15//start
16 mToastRunnable.run();
17
18//stop
19 mHandler.removeCallbacks(mToastRunnable);