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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:22:41+00:00 2026-05-26T22:22:41+00:00

Using Android 2.1+. I have a service that gets killed from time to time

  • 0

Using Android 2.1+. I have a service that gets killed from time to time by the OS (due to memory pressure I guess).

This service maintains some states using static member fields of classes. I’m expecting the static fields to keep their values despite the service being killed and restarted by the OS.

But it seems that it doesn’t happen like this. After a restart, static variables are reset to default value.
Is it what is supposed to happen? Should I use another way to keep a persistent state despite kill/restart?

  • 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-26T22:22:41+00:00Added an answer on May 26, 2026 at 10:22 pm

    Yes, this is what happens when your service is killed. The program is taken out of memory, and when it’s reloaded into memory, the default values for the static variables are all assumed. Put another way, the byte code for your program can’t change from execution to execution.

    It’s generally considered bad from to use static variables to keep state. Try storing them in presistent storage, like a sqlite database.

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

Sidebar

Related Questions

I have an Android app that fetches data from the web service using ksoap2,
I have an android application that gets user location every 2 minutes using requestLocationUpdates
Using android 2.3.3, I have a background Service which has a socket connection. There's
I'm trying to call a RESTful web service from an Android application using the
I have an Android app that talks to .net web service via http over
I have a web app, that also has an iPhone and Android app using
This question concerns memory in Android. My method: I have two activites, A and
I have a Service that is, for this discussion, holding a number and a
first, a little background. I am using VS2010 and have a WCF service that
I have implemented a web service(.asmx) using .NET framework that returns me a hash

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.