I am running multiple thread and Handler in my code.
And this is my Handler
PrizeRunnable mTempPotionRunnable = new PrizeRunnable(aaa);
handler.postDelayed(mTempPotionRunnable, 4000);
and
class PrizeRunnable implements Runnable {
String type;
PrizeRunnable(String type) {
this.type = type;
}
public void run() {
synchronized (this) {
if(!mIsHandlerStarted){
if(type.equals(aaa))
// Do something
else if(type.equals(bbb))
// Do something
mIsHandlerStarted = true;
handler.removeCallbacks(this);
}
}
}
}
But sometime it run simultaneously.
i don not know the reason.
UPDATED
I try to change it to:
handler.postDelayed(mTempPotionRunnable, 4000);
and
Runnable mTempPotionRunnable = new Runnable() {
@Override
public void run() {
synchronized (this) {
if(!mIsHandlerStarted){
// Do something
mIsHandlerStarted = true;
handler.removeCallbacks(mMetalRunnable);
}
}
}
};
May be it resolve my problems. I am testing this method.
But i can’t pass parameter to my Runnable . How can i do it?
Make global variable and i can pass parameter to my
Runnable