Change ImageView for a few seconds and pause UI
-
28-10-2019 - |
Question
Sorry, I keep on trying to adapt the tokens, but somehow I can't manage this one.
I have the following code:
timer.schedule(new TimerTask(){
runOnUiThread(new Runnable() {
public void run(){
SplashImage.setImageDrawable(aktieknop);}
});
},SplashTime);
}
Like this the code 'works':
timer.schedule(new TimerTask(){
// runOnUiThread(new Runnable() {
public void run(){
SplashImage.setImageDrawable(aktieknop);}
// });
},SplashTime);
}
Can you please help me solving this silly issue? Thanks a lot!
Solution
You must call this code line " SplashImage.setImageDrawable(nSplashImage);
" from your run method in a runOnUIThread() method like this:
runOnUiThread(new Runnable() {
public void run() {
SplashImage.setImageDrawable(nSplashImage);
}
});
This is because you cannot change UI components on a non UI thread.
OTHER TIPS
For the splash Screen you can use the Handler and send the delayed message.
Handler splashHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
//Here you can do what ever you want
}
};
int SPLASHTIME=2000;//your wish
splashHandler.sendMessageDelayed(msg, SPLASHTIME);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow