I have button called color. How can I change the Activity background color every 5 seconds?
Asked
Active
Viewed 598 times
3 Answers
2
Quick google search: How to set background color of an Activity to white programmatically?
Put that in a loop with a Thread.sleep(5000)
and wrap it with a function that sets the colors you want.
1
Do not sleep a thread , its a bad practice Create the object of your parent view in layout and use Async task to update the UI after a fixed interval in below method
protected void onProgressUpdate(Integer... progress) {
// interact with UI here
}
see the docs for AsyncTask implementation.

Jitender Dev
- 6,907
- 2
- 24
- 35
0
You could use TimerTask
e.g.
Time timer = new Timer();
timer.scheduleAtFixedRate( new TimerTask(){
public void run(){
//here set background
}
},0,5000);
For more details, http://developer.android.com/reference/java/util/Timer.html

MikeKeepsOnShine
- 1,730
- 4
- 23
- 35