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

  • SEARCH
  • Home
  • 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 8295559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:38:56+00:00 2026-06-08T14:38:56+00:00

I am trying to get notification whenever a new email arrives in inbox, code

  • 0

I am trying to get notification whenever a new email arrives in inbox, code is given below. My application becomes irresponsive after short time, although in logCat application is still communicating with the imap server….but android system ask me to either wait or close this application. Is this because of the “thread.sleep()”? How can I solve it?

Can any one guide me? :/

@Override

public void onStart(Intent intent, int startid) {
    Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
    Log.d(TAG, "onStart");
    //player.start();
    //add listenser and keep listening
    try{
        folder.addMessageCountListener(new MessageCountAdapter() {//start
            public void messagesAdded(MessageCountEvent ev) {
                Message[] msgs = ev.getMessages();
                // msgs.length

                Log.d(TAG, "It is inside LISTENER");

            }
            });//end    
         for (; ;) {
                Thread.sleep(20000); // sleep for freq milliseconds

                // This is to force the IMAP server to send us
                // EXISTS notifications. 
                Log.d(TAG, "AFTER SLEEP");
                folder.getMessageCount();
                }
    }
    catch(Exception e){

    }

}
  • 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-06-08T14:39:01+00:00Added an answer on June 8, 2026 at 2:39 pm
    1. onStart is deprecated. You should use onStartCommand instead.

    2. The system calls both onStart and onStartCommand on the main UI Thread. The reason why your app is appearing to be “irresponsive” is because you are calling Thread.sleep(20000) on the main UI thread. The main UI thread is responsible for generating your layouts and responding to touch/UI events. The call to Thread.sleep is preventing all of this from happening, and thus your app appears to be hang (and eventually you get an Application Not Responding error).

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

Sidebar

Related Questions

I'm trying to get the notification NSTaskDidTerminateNotification in my multithreaded app but I can't
I'm trying to make a notification in Android. But i get the error in
I am using pynotify and this is the code I am trying to get
I´m new to PhoneGap/CoffeeScript trying to get a Hello World App running in iOS
I am trying to get a notification when an user comments using the social
I'm trying to get notifications whenever the master volume changes on Windows Vista/7. This
I'm trying to get a notification from a MPMoviePlayerController when the movie has reached
I'm trying to get my Notification to not cancel when the user presses Clear
I have enabled notification on AppFabric and I'm trying to get notified when an
Basically I'm trying to get the notifications present in the notification bar somewhere else,

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.