I want to make an app that displays some info on the screen, waits a while and then continue to display something else. Is there a simple command to pause an android app? I'm using android 4.2.2.
Asked
Active
Viewed 2,890 times
3 Answers
3
You can use Handler class:
Make an instance:
Handler h=new Handler();
Use your instance to run the postDelayed() method:
final boolean postDelayed(Runnable r, long delayMillis)
Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.
The postDelayed() method has to be feeded with a Runnable containing the code which you want to occur after the delayMillis milliseconds.
The runnable class can be made as following:
class Runner extends Runnable{
public void run() {
//Your codes
}
}
As a simple example:
Handler handler = new Handler();
handler.postDelayed(new Runner(), 2000);

Aniruddha Sarkar
- 1,903
- 2
- 14
- 15
-
Thanks! The view I used also contained the postDelayed() method, so I used that one. – Frank Jul 28 '14 at 07:03
1
You can do this by removing the timer ..
Sample code
@Override
public void onClick(View v) {
my_button.setBackgroundResource(R.drawable.icon);
// SLEEP 2 SECONDS HERE ...
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
my_button.setBackgroundResource(R.drawable.defaultcard);
}
}, 2000);
}
Am not an android developer..I recommend you to read this.I got the answer from there ..Hope it helps ..

Community
- 1
- 1

Avinash Babu
- 6,171
- 3
- 21
- 26
1
You could use Thread.sleep()
try {
Thread.sleep(milliseconds);
} catch (InterruptedException e) {
e.printStackTrace();
}
There might be better ways but this is the one I learnt.

Chrome Penguin Studios
- 156
- 1
- 6