Also, if you just want to dismiss the window after a timeout, you
don't need to use a thread at all, just create a Handler in the
current (main thread) and post a delayed message or runnable to it.
See the use of sendMessageDelayed() here for an example:

http://code.google.com/android/samples/ApiDemos/src/com/example/android/apis/app/RemoteService.html

On Oct 6, 8:33 am, "Romain Guy" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> You can use threads but all the views, and all the views related APIs,
> must be invoked from the main thread (also called UI thread.) To do
> this from a background thread, you need to use a Handler. A Handler is
> an object that will post messages back to the UI thread for you. You
> can also use the various post() method from the View class as they
> will use a Handler automatically. In your case, you could do something
> like this:
>
> private Handler mHandler;
>
> protected void onCreate(Bundle saved) {
>    mHandler = new Handler();
>
> }
>
> // In your Thread
> public void run() {
>    // ...
>   mHandler.post(new Runnable() {
>     public void run() { popup.dismiss(); }
>   });
>
> }
>
> You can also look at the class called UserTask from the
> apps-for-android 
> project:http://code.google.com/p/apps-for-android/source/browse/trunk/Photost...
>
> It makes threading/UI interactions even easier.
>
>
>
> On Mon, Oct 6, 2008 at 8:25 AM, Falko Richter <[EMAIL PROTECTED]> wrote:
> > Hello everyone,
>
> > I first have a general question if threaded programming is possible with the
> > Android Platform?
>
> > Secondly I have a specific problem. I have an application that gives the
> > user feedback with a "PopupWindow". By standart the Popup disappears then
> > the user clicks somewhere on the screen. I want to make the popup
> > automatically after X millisecond, so I programmed myself a little thread:
>
> > package com.fon;
> > import android.util.Log;
>
> > public class PopupThread extends Thread {
> >     fonPopupWindow popup;
> >     long millis;
>
> >     public PopupThread(fonPopupWindow popup) {
> >         this.popup = popup;
> >     }
>
> >     public void run() {
> >         try {
> >             sleep(millis);
> >             popup.dismiss();
> >         }
> >         catch(InterruptedException e) {
> >         }
> >     }
> > }
>
> > but everytime the thread tries to dismiss my popup, I get the following
> > exception:
>
> > android.view.ViewRoot$CalledFromWrongThreadException: Only the original
> > thread that created a view hierarchy can touch its views.
>
> > From what I understand, this tells me that I cannot access something outside
> > the new created Thread, and therefore my plan is immpossible to solve on
> > Android.
>
> > Thx for suggestions
>
> > Falko
>
> --
> Romain Guywww.curious-creature.org
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to