I solved this using AsyncTask, thanks both for replying

On Nov 13, 2:20 pm, Stelios <s.kiay...@gmail.com> wrote:
> I am a beginner in Android platform and i have encountering a serious
> problem. I want to fetch emails from gmail and therefore i have
> created a class that does that. However when i run my class in android
> NetworkOnMainThreadException. So i have created new Thread with a new
> Runnable as below :
>
> public void onClick(View v) {
>   new Thread(new Runnable() {
>     public void run() {
>       FetchEmails e = new FetchEmails();
>     }
>   }).start();
>
> }
>
> It worked fine but then i can't seem to have access to e.getMessage in
> order to get the actual email. Having this on mind i have implement
> Runnable to my FetchEMails class and done all the fetch code in run()
> which i have overidden. The last piece of code in run() is setting a
> variable to 'true'. Then in my Activity class i have instantiate the
> class and i have done this : new Thread(e).start();. Below i have a
> while loop to check wether the class has finished to the end of run()
> method (by checking if the variable is true). So now i have created my
> new theard which does not intefere with the UI and when the code is
> finished i want to get the message. But it seems that i still get the
> NetworkOnMainThreadException error. Any help with that is apprecieted.
> Thanks.

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

Reply via email to