kaloer wrote:
> Hi,
> I am using a Timer in my android application, but i can't get it to
> work. When I start my application the Timer simply does not start. The
> application continues but does not update.
>
> The long "toStart" finds the number of seconds left of the current
> minute, and thereafter the period is set to 60 seconds. The TimerTask
> simply calls a method.
>
> This is the first part of the class containing the Timer:
>
> public class infoUpdate extends Activity {
>
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
> final Calendar cal = Calendar.getInstance();
> updateTime();
> long toStart = ( 60 - cal.get(Calendar.SECOND) ) * 1000;
> Timer firstTimer = new Timer(false);
> firstTimer.schedule(new TimerTask() {
> @Override
> public void run() {
> updateTime();
> }
> }, toStart, 60000);
> }
In your code, your Timer instance is defined as local to onCreate()
instead of being a data member of the class. Hence, when onCreate()
ends, your Timer goes away.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---