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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:30:22+00:00 2026-06-18T03:30:22+00:00

My android app got killed in background within 5 to 10 minutes if network

  • 0

My android app got killed in background within 5 to 10 minutes if network is not available.

App constantly calls some rest services in background.

I am not getting any exception in my logcat.

But when I comes back in foreground my app starts from beginning because its killed by OS.

Please suggest me what might be the cause and What should I do to prevent it.

public void sendHttpPost() throws ClientProtocolException, IOException{
        HttpPost httpPostRequest = new HttpPost(url + buildParams());

        // add headers
        HttpParams httpParams = new BasicHttpParams();
        Iterator it = headers.entrySet().iterator();
        Iterator itP = params.entrySet().iterator();
        while (it.hasNext()) {
            Entry header = (Entry) it.next();
            httpPostRequest.addHeader((String)header.getKey(), (String)header.getValue());
        }
        while(itP.hasNext())
        {
            Entry header = (Entry) itP.next();
            StringEntity se = new StringEntity((String) header.getValue());
            httpPostRequest.setEntity(se);
        }
        HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
        HttpConnectionParams.setSoTimeout(httpParams, 30000);
        httpPostRequest.setParams(httpParams);
        HttpClient client = new DefaultHttpClient();
        HttpResponse resp;

        resp = client.execute(httpPostRequest);

        this.respCode = resp.getStatusLine().getStatusCode();
    //  Log.i(TAG, "response code: " + getResponseCode());
        this.responsePhrase = resp.getStatusLine().getReasonPhrase();
    //  Log.i(TAG, "error msg: " + getErrorMsg());
        HttpEntity entity = resp.getEntity();

        if (entity != null){
            InputStream is = entity.getContent();
            //Header contentEncoding = resp.getFirstHeader("Content-encoding");
            //Log.i(TAG, "endoding" + contentEncoding.getValue());
            response = convertStreamToString(is);
            //response = response.substring(1,response.length()-1);
            //response = "{" + response + "}";
    //      Log.i(TAG, "response: " + response);
            screen.update("Login", response, false);
            is.close();
        }
    }

This is the method which interact with server even if network is not available

and below is the code where a thread calls rest services.

How to do same with services:

public void start()
    {
        try{

            if(_exit)
                return;      
            //_lastExecute = System.currentTimeMillis();
            _try++;
        //  Log.i("-----HK Requests--------- \n\r", _url);
            final String response = HttpConnector.callWebService(_url, _data, _listener, _token);

            CallBackThread ct = new CallBackThread(_action, response, autocallreq);
            ct.start();         
//          while(ct.isAlive())
//          {
//              Thread.sleep(500);  
//          }
        }        

        catch(Exception e)
        {
            System.out.print("error="+e.getMessage());
            Helper.LogException(this, e);
            //CallBackThread ct = new CallBackThread(_action, "", autocallreq);
            //ct.start();
        }
    }

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-06-18T03:30:23+00:00Added an answer on June 18, 2026 at 3:30 am

    My android app got killed in background within 5 to 10 minutes if network is not availabale

    that’s what suppose to happen when your app don’t have any forground Activity or forground Service instances.
    that’s also depends on how much memory you app consuming in background – the OS will put your app in high priority to be “killed” first if consumes a lot of memory.

    this Google IO video explains more about when your app could be killed in such situation – http://www.youtube.com/watch?v=gbQb1PVjfqM&list=PL4C6BCDE45E05F49E&index=10&feature=plpp_video

    that’s two or three minutes discussing about this issue in the middle of the video

    App constantly calls some rest services in background

    if you are not doing the calls to the REST methods from android Service class – you should do it, because as I said – the OS will kill your process very fast if no Activity is forground or no forground Service is running,

    I must say that running background service that doing for long period of time network operations in background – is a bad idea anyway: it will consume a lot of battery, and also 3G bandwidth. users will delete your app very fast after they will realize it draining thier battery. so you should be carful from doing too much in background

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

Sidebar

Related Questions

My android app used to got killed in background even with foreground service. Here
I've got an Android app which has a periodic background Service. I want this
I've got some basic Java experience and very basic Android app development experience (currently
I've got some XML resources in my Android app. Each one has a different
I programmed an App for Android and got some trouble with my Service. The
I'm writing my first location based android app, but got confused about some of
I've got the following to open up a browser from within an Android app.
I have got some inapp billing in my Android app. When the user clicks
Hey I've got this problem: In my Android App there's a method that calls
I've got a native Android app that contains a WebView. All my HTML, js

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.