>From my experience, timers are a finicky thing in android. I have
always had much better luck using a postDelayed to a handler.

public class MyClass extends Activity
{
        private Handler objHandler = new Handler();

        public void MyFunction()
        {
                //Or put this in your onCreate()
                objHandler.postDelayed(doTasks, 60000);
        }


        private Runnable doTasks = new Runnable()
        {
                public void run()
                {
                        Context context = getApplicationContext();

                        Toast toast = Toast.makeText(context, strMsg, 100);

                        toast.show();

                        //And if you want it to fire again do this, otherwise 
delete this
line
                        objHandler.postDelayed(doTasks, 60000);
                }
        };



        //And you can destroy the call back with a user interaction if you
want
        private void SomeUserFunction()
        {
                objHandler.removeCallbacks(doTasks);
        }
}

On Feb 6, 8:38 pm, Xin Zhao <uszhao...@gmail.com> wrote:
> I tried to deploy a timer and switch the user to another dialog for setting
> if times out. But the dialog just cannot display. No error/exception
> reported. Vibration works fine though.
>
> What's wrong?
>
> Code:
>
>   private void setAutoPhonecardSelector(int interval) {
>     Date timeToRun = new Date(System.currentTimeMillis() + interval);
>     Timer timer = new Timer();
>
>     mAutoPhonecardSelector = new TimerTask() {
>       @Override
>       public void run() {
>         mVibrator.vibrate(100);
>         Toast.makeText(PhoneCardSelector.this, "test",
> Toast.LENGTH_LONG).show();
>       }
>     };
>
>     timer.schedule(mAutoPhonecardSelector, timeToRun);
>   }
>
> Please help!
>
> Thanks in advance!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to