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 8017885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:58:08+00:00 2026-06-04T20:58:08+00:00

I have a service which works with LongPoll and when I receive my data

  • 0

I have a service which works with LongPoll and when I receive my data everything is OK, but when I don’t receive data, rather I receive empty result (long polling max time == 25 sec) my service sometimes turning off manually (and I don’t see it in list of services).

So, how to keep this service (..always..) running?

Recursive function, which works with long polling and at first calls in service’s onCreate() (structure):

//"u" is "new utils()".
public class myservice extends Service {
  public static boolean started=false;
  @Override
  public void onCreate() {
    super.onCreate();
    Toast.makeText(this, "created qweqwe", Toast.LENGTH_LONG).show();
    longpoll();
    this.started=true;
  }
  @Override
  public void onDestroy() {
    super.onDestroy();
    this.started=false;
  }
  private String url = "http://example.com/lp.php";
  private void longpoll() {
    try {
      String resp = u.getData(url); //max time of working u.getData(lpurl) - 25s.
      if (resp.length()>0) doSmthWithData(resp); //It works fine
    } catch(Exception e) {}
    longpoll();
  }
}
  • 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-04T20:58:09+00:00Added an answer on June 4, 2026 at 8:58 pm

    So, how to keep this service (..always..) running?

    Tactically, based on the “15 seconds” in your question title, my guess is that you are doing this long poll on the main application thread. You need to do it on a background thread.

    Strategically, you cannot keep a service “always running”. You can use startForeground() to reduce the odds of your service being automatically destroyed, but the user and the OS can still get rid of your process (along with its service) at any time for any reason. Many users do not like services that are “always running” because of the resources they waste, and therefore will attack developers of such services with task killers and low ratings on the Play Store.

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

Sidebar

Related Questions

I have the following web-service which works perfectly as long as it is accessed
I have a WCF service, which works if I use one login, but throws
I have an SQL query which works fine in DB2 My result is SERVICE
I have a WCF service which works on my dev machine running IIS 7,
I have a windows service application which works using remoting. It is used to
I have a windows service which fetches data from various datasources and build a
I have a WCF service which performs CRUD operation on my data model: Add,
I have set up a CXF web service which works well. My service primarily
I have a service which contains a Timer and TimerTask for receiving data from
At my current place of work we have to use a web-service which works

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.