1

I've tried time&timertask, handler&runnables, nothing makes my function be called after certain time. Please, help me get rid of this.

when = System.currentTimeMillis();
t1 = new Timer();
tt = new TimerTask(){@Override public void run(){ systemClick();}};
t1.scheduleAtFixedRate(tt, when+interval, interval);

And this one:

final Handler myHandler = new Handler();

    Runnable runnableforadd  = new Runnable() 
    {
        public void run() 
        {
            systemClick();              
            myHandler.postDelayed(this, interval);
        }   
    };
    myHandler.postDelayed(runnableforadd, when + interval);

Both the first and the second I execute in onCreate(). systemClick() doesn't get called even for a one time in deed (I've put Toast in there). I don't understand in Threads well.

systemClick - is a function, where system performs click of my button - myButton.performClick() is called there (and other functions as well).

How can I solve this?

Thanks

azizbekian
  • 60,783
  • 13
  • 169
  • 249

2 Answers2

1

The value in delay time should be the value that you want your method to wait for. For example if you want to call your method after waiting 1 minute then pass 60000.

myHandler.postDelayed(runnableforadd, 60000);

Currently you are adding "wait" in the delay time that is System.currentTimeMillis() which means your method will be called after approx "1338900000000" milliseconds

rizzz86
  • 3,862
  • 8
  • 35
  • 52
0

have you tried AlarmManager. AlarmManager will help you execute your piece of code after certain period.

Sana
  • 9,895
  • 15
  • 59
  • 87