Friday, November 30, 2012

[android-developers] thread wait in android

i have one problem with handling the thread in android ,in my class i have to create one thread which create some UI after that thread finish i will get some value ,here i want to wait my Main Process until the thread complete it process but when i put wait() or notify in Main process  thread does not show the  UI  in my application

this is sample code

    protected void onCreate(Bundle savedInstanceState) {
   
    downloadThread = new MyThread(this);
    downloadThread.start();
    
    synchronized(this){  
    try {
    this.wait();
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
   
     String test=Recognition.gettemp();
    public class MyThread extends Thread {
    private Recognition recognition;
    
    public MyThread(Recognition recognition) {
    this.recognition = recognition;
    // TODO Auto-generated constructor stub
    }
    
    @Override
    public void run() {
    synchronized(this)

    {                
                                                   
    handler.post(new MyRunnable());
   
    }
   
    notifyAll();
    }
    }
    }
    static public class MyRunnable implements Runnable {
    public void run() {
    settemp(template);
    }
    
    }
    }
    
    public static String gettemp() {
    return template;
    }
    public static void settemp(String template) {
    Recognition.template = template;
    }
    
    }
here i will not use AsynTask because i have some other issue that is reason i choose Thread even now the problem is Thread wait do any give the suggestion for this

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment