Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6805183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:33:21+00:00 2026-05-26T19:33:21+00:00

I am a beginner in Android platform and i have encountering a serious problem.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:33:22+00:00Added an answer on May 26, 2026 at 7:33 pm

    You should be using an AsyncTask instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner on android platform, and I want to build a tracerouting
I'm making a simple 2d game for the android platform, which works perfectly from
I am a beginner in Android programming. I want to build a simple application
Beginner here, I have a simple question. In Android what would be the best
I am a Java beginner , I want to develop Android app , what
I am a beginner android developer and I am trying to have a button
I'm beginner of Android. I want to run my first application on emulator. I
I'm a beginner in android and i tried running some code I got from
I am a beginner of Android apps and am using Eclipse. I have found
I'm a beginner in Android. I created two interfaces with DroiDraw, then I added

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.