I want to wait inside my while loop for like 1 second each time it is inside the loop.
I tryed with Runnable:
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
int i=0;
while(i<10){
if(i%2 ==0){
myTextView.setText("true");
}
else{
myTextView.setText("false");
}
i++;
}
}
}, 1000);
If i ran this code i got a blank display for minutes and then a crash.
Logcat:
ActivityManager Reason: keyDispacthingTimeot
What is the problem?
I would like to make this as simple as it can be…
Please help!
If you want to make sthg very simple, then just use
Note: as Adeel said, do not sleep in a UI thread =)
EDIT: you should implement sthg like this:
I think you want to use a
asyncTask, andpublishprogresseach one sec. So make your ownasyncTask<Void, Integer, Void>, and on thedoInbackgroundmethod:Then implement the
onProgressUpdatemethod which runs on UI thread, and:Here is the doc about asynctasks