Skip to content

Instantly share code, notes, and snippets.

@SOF3

SOF3/handle.java Secret

Created September 18, 2016 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SOF3/07c3c110aa214fcdd752e95573b7076f to your computer and use it in GitHub Desktop.
Save SOF3/07c3c110aa214fcdd752e95573b7076f to your computer and use it in GitHub Desktop.
public class handle{
private boolean done = false;
public void onClick(View v){
final Handler handler = new Handler();
final Random random = new Random();
Runnable toast = new Runnable(){
@Override
public void run(){
if(done){
Toast.makeText(getBaseContext(), "Done", LENGTH_SHORT).show();
}else{
Toast.makeText(getBaseContext(), "Please wait", LENGTH_SHORT).show();
handler.postDelayed(this, 1000);
}
}
};
Runnable yourFunc = new Runnable(){
private int count = 0;
@Override
public void run(){
count++;
runYourFunc();
if(count >= 20){
done = true;
}else{
handler.postDelayed(this, random.nextInt(5000));
}
}
}
runnable.run();
handler.postDelayed(yourFunc, random.nextInt(5000));
}
private void runYourFunc(){
// your function here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment