Try using the alarm service or use a hanlder with postDelayed (). J2SE things may be supported in Android, but you don't always get the same result, particularly with issues involving threads.
M On Dec 8, 7:45 pm, Xiongzh <[EMAIL PROTECTED]> wrote: > Hi, > > I was going to update the 'hello world' message in a edit text box by > java.util.Timer. > But it did not work as in a simple Java application. > Maybe the way in Android is to put the timer in a service. > But I'll like to know the reason: why does java.util.Timer not make > sense in Activity? > > Thank you in advance. > > package com.example.android.helloactivity; > > import java.util.Timer; > import java.util.TimerTask; > > import android.app.Activity; > import android.os.Bundle; > import android.widget.EditText; > > /** > * A minimal "Hello, World!" application. > */ > public class HelloActivity extends Activity { > > private Timer helloTimer = new Timer(); > int seq = 0; > > public HelloActivity() { > } > > @Override > protected void onResume() { > sayHelloWorld(); > helloTimer.schedule(new TimerTask() { > > @Override > public void run() { > System.out.println("timer run"); > sayHelloWorld(); > } > > }, 3000, 1000); > super.onResume(); > } > > @Override > protected void onPause() { > helloTimer.cancel(); > super.onPause(); > } > > private void sayHelloWorld() { > EditText helloEditText = (EditText)findViewById(R.id.text); > helloEditText.setText("Hello world " + (++seq)); > helloEditText.invalidate(); > } > > /** > * Called with the activity is first created. > */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > // Set the layout for this activity. You can find it > // in res/layout/hello_activity.xml > setContentView(R.layout.hello_activity); > } > > > > }- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---