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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:09:36+00:00 2026-06-06T18:09:36+00:00

I have a small data collection app which has a single button to start

  • 0

I have a small data collection app which has a single button to start and stop a service.

The service in turn starts a new thread. Which collects data about voltage changes whenever there is a broadcast about it.

Data is temporarily stored in a ArrayList, and every 10 seconds the all the data stored in arrayList is dumped into a database.

App is running fine for 10-20 min but after 20 min app automatically stops. Some times service is still running and some times service is also killed.

Can you guys tell me what could be the problem here.
Things I think might relate to this problem are:

1.> I am opening and closing database every 10 sec. Should I change the design to close database only when the whole app is finished.

2.> I also took a wakelock, but that didnt make any difference. Should I take wakelock for my service also ?

3.> And lastly how can I come to know about the error because of which my app stopped( I can not connect to USB to know that coz I want battery to be in draining mode)

Update:

The logcat error is as follows:

E/AndroidRuntime( 9770): FATAL EXCEPTION: Timer-0
E/AndroidRuntime( 9770): java.util.ConcurrentModificationException
E/AndroidRuntime( 9770):    at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:569)
E/AndroidRuntime( 9770):    at com.amazon.hsyal.services.LoggerThread$2.run(LoggerThread.java:78)
E/AndroidRuntime( 9770):    at java.util.Timer$TimerImpl.run(Timer.java:284)
W/ActivityManager(  236):   Force finishing activity com.amazon.hsyal/.ui.VoltageSODLoggerActivity
I/ActivityManager(  236): No longer want com.amazon.dcp:OTAService (pid 12299): hidden #16
I/WindowManager(  236): WIN DEATH: Window{417dcd20 com.amazon.hsyal/com.amazon.hsyal.ui.VoltageSODLoggerActivity paused=true}
I/UsageStats(  236): No package stats for pkg:com.amazon.kindle.otter
I/ActivityManager(  236): Process com.amazon.hsyal (pid 9770) has died.
W/ActivityManager(  236): Scheduling restart of crashed service com.amazon.hsyal/.services.LoggerService in 5000ms
I/ActivityManager(  236): Start proc com.amazon.kindle for broadcast com.amazon.kindle/.PrimeAppReceiver: pid=13075 uid=32022 gids={3003, 1015}
W/ActivityManager(  236): Activity pause timeout for ActivityRecord{4173eb10 com.amazon.kindle.otter/.Launcher}
I/ActivityManager(  236): Start proc com.android.settings for broadcast com.android.settings/.TopWindowChangereceiver: pid=13111 uid=1000 gids={1015, 3002, 3001, 3003}
I/ActivityManager(  236): Start proc com.amazon.hsyal for service com.amazon.hsyal/.services.LoggerService: pid=13138 uid=10051 gids={}
W/ActivityManager(  236): Activity destroy timeout for ActivityRecord{41750838 com.amazon.hsyal/.ui.VoltageSODLoggerActivity}

and the corresponding Thread code is as follows:

public void run() {
    // TODO Auto-generated method stub
    dbInstance = new DbClass(ctx);
    Log.d("Debuglogger","Came inside thread");
    ctx.registerReceiver(this.voltageReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            if(threadStatus == false){
                return;
            }
            if(!DataClass.dataList.isEmpty()){
                dbInstance.open();
                Iterator<DataClass> itr = DataClass.dataList.iterator();
                DataClass a_temp;
                while(itr.hasNext()){
                    a_temp = itr.next();
                    dbInstance.createEntry(a_temp.getVoltage(), a_temp.getCurrent(), a_temp.getBattery_level(),
                            a_temp.getTime(), a_temp.getRtime());
                }
                dbInstance.close();
                DataClass.dataList.clear();
                Log.d("db-error", "Data written to database and list cleared !");
            }
        }}, 0, UPDATE_INTERVAL);
}
  • 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-06T18:09:37+00:00Added an answer on June 6, 2026 at 6:09 pm

    As you can see from the stack trace, the error seems to be java.util.ConcurrentModificationException as you are accessing the ArrayList from multiple threads. You can take a look at How to Avoid ConcurrentModificationException when using an Iterator, the relevant part of which is as below:

    To Avoid ConcurrentModificationException in multi-threaded environment:

    1. You can convert the list to an array and then iterate on the array. This approach works well for small or medium size list but if the list is large then it will affect the performance a lot.

    2. You can lock the list while iterating by putting it in a synchronized block. This approach is not recommended because it will cease the benefits of multithreading.

    3. If you are using JDK1.5 or higher then you can use ConcurrentHashMap and CopyOnWriteArrayList classes. It is the recommended approach.


    1.> I am opening and closing database every 10 sec. Should I change the design to close database only when the whole app is finished.

    There is not so much of an overhead to open and close the database every 10s. Think of this only if you have a performance issue.

    2.> I also took a wakelock, but that didnt make any difference. Should I take wakelock for my service also ?

    Does not seem to be related to the particular issue.

    3.> And lastly how can I come to know about the error because of which my app stopped( I can not connect to USB to know that coz I want battery to be in draining mode

    Hope you have already understood how this can be done. Just to reiterate, you can obtain logcat output even after the application has stopped – either through DDMS or using the adb command : adb logcat -d > log.txt

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

Sidebar

Related Questions

We have a small java based server (a simple app which fetches data using
I have a small database with tables containing a small amount of data which
Hi i have a small query which takes data from one mysql database and
I'm writing small VB.Net app which should build reports based on data gathered from
I have a small app/site on a dev server with a data table in
So I have a small little app which downloads a very small amount of
I have written a small android app that grabs some data and displays it
We have a small data set and would like to search through it in
I have a small data conversion application that converts xml into a json then
We do have a small data warehouse in PostgreSQL database and I have to

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.