I want to set the background of my application dynamically, depending on daytime. This should be checked periodically. Therefore I start this runOnUiThread():
class BackgroundMainThread implements Runnable {
// @Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
Thread.sleep(1000);
doBackgroundImage();
Thread.sleep(30000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
Log.e("log_tag2", "Error is " + e.toString());
}
}
}
}
public void doBackgroundImage() {
runOnUiThread(new Runnable() {
public void run() {
try {
//final FrameLayout framelayout_main_bild = (FrameLayout)findViewById(R.id.framelayout_main);
//framelayout_main_bild.setBackgroundResource(PictureresID);
findViewById(R.id.framelayout_main).setBackgroundDrawable(getResources().getDrawable(R.drawable.picture1));
} catch (Exception e) {
}
}
});
}
I'm running other Threads as well and everything works fine, but only when running this thread the following error occurs:
Skipped 40 frames! The application may be doing too much work on its main thread.
Any idea how to solve that?
0 comments:
Post a Comment