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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:40:55+00:00 2026-06-13T14:40:55+00:00

I have a problem regarding the lifetime of a variable. My Android-App should write

  • 0

I have a problem regarding the lifetime of a variable.

My Android-App should write sensor-data to a file and send this file to a server. For this I created a Activity (Main-Activity) and two Services. One is for writing the sensor-data to files (Sensor-Service) and one for sending the files to a server (Upload-Service). The activity has two toggle-buttons for start/stop the two services seperately.

The communication between the two services works with a list:
When a new file with sensor-data is ready (has a particular size) the name of the file is appended to a list.
The Upload-Service checks in an infinite-loop if new files are in the list and uploads them.

But this list causes a problem:
When my App runs in Background and I open many other Apps at some point the reference on the list becomes NULL in Sensor-Service (and probably also in Upload-Service).

The list is defined in the Main-Activity:

private static LinkedBlockingDeque<String> mFileSendQueue;

and initialised in onCreate of the Main-Activity:

mFileSendQueue = new LinkedBlockingDeque<String>();

and passed to the two Services via a static method setQueue (both services contain such a method):

public static void setQueue(LinkedBlockingDeque<String> queue) {
    mFileSendQueue = queue;
}

I know that the Activity can be closed by Android e.g. if space is required, but in my opinion the list shouldn’t be deleted as long as there is at least one reference to it.
Does anybody know what my mistake is?

Thanks for reading

  • 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-13T14:40:56+00:00Added an answer on June 13, 2026 at 2:40 pm

    Id recommend that your “sender service” keeps record itself. You could name files by timestamps and the sender stores the last timestamp that was uploaded.

    Android / dalvik vm seems to delete references after some time in the background. I’ve seen it happen in my services, suddenly hardware sockets are null etc.

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

Sidebar

Related Questions

I have a problem regarding Android App. I have created an application that download
I have problem regarding insert operation in SQL Server CE, this is the exception
I have a problem regarding android database.I have an app which have it's database
I have a cross-language problem regarding md5 :). I have this code in Java:
I have a problem regarding submitting multiple locale translations for model data within the
I have a problem regarding multiple inclusion of header file in C++ code. Say
I have a problem regarding putting a PID controller in my simulink file. In
I have one problem regarding the data insertion in PHP. In my site there
I have a problem regarding fetching the data of the last one month. As
I have a problem regarding return data using JSON. How do i get the

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.