Don't use the alarm manager for this kind of thing. The best thing is to use Handler with delayed messages.
And Timer works fine, the problem is that a Timer runs in a separate thread, and so you are trying to modify a view owned by another thread (the main thread that originally created it). On Tue, Dec 9, 2008 at 1:11 PM, Mark K <[EMAIL PROTECTED]> wrote: > > > 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 - > > > -- Dianne Hackborn Android framework engineer [EMAIL PROTECTED] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---