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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:13:43+00:00 2026-05-28T00:13:43+00:00

I have an app that works on the emulator but will intermittently crash when

  • 0

I have an app that works on the emulator but will intermittently crash when testing on a real device. I am running a modified version of Code Overtones Android Crash report. (http://jyro.blogspot.com/2009/09/crash-report-for-android-app.html) The emailed cause states:

The content of the adapter has changed but ListView did not receive a
notification. Make sure the content of your adapter is not modified
from a background thread, but only from the UI thread. [in
ListView(2131296303, class android.widget.ListView) with Adapter(class
android.widget.SimpleAdapter)]

The code does not modify the adapter outside of the UI main thread. All access to the adapter is through the onPostExecute of an AsyncTask. The code is:

    @Override
    protected void onPostExecute(String result) {
        MyLog.d(TAG, "onPostExecute");
        foodDescArrayList.clear();
        int entries = holdFoodDescArrayList.size();
        HashMap<String, String> listEntry;
        for (int i = 0; i < entries; i++) {
            listEntry = new HashMap<String, String>();
            listEntry = holdFoodDescArrayList.get(i);
            foodDescArrayList.add(listEntry);
        }
        holdFoodDescArrayList.clear();
        hideProgress();
        foodDescAdapter.notifyDataSetChanged();
        String ents = " entries";
        if (rowsReturned == 1) {
            ents = " entry";
        }
        foodDescHeader.setText("Page " + Integer.toString(currentPage + 1)
                + " of " + Integer.toString(pageCount) + " (" + Integer.toString(rowsReturned) + ents + ")");
        loadActive = false;
    }

The holdFoodDescArrayList is a stand alone list filled in the background task from an SQLite database. the foodDescArrayList is the array associated with the ListView adapter. (I’ve found that there is a performance boost when queuing this way. Maybe because the adapter is out of the loop during database access. Less overhead?)

The crash always occurs on first entry (onCreate) after a home key exit and then reentry to the top level activity that calls the list activity. The time between crashes is from 30 minutes to 2 hours during continuous testing. The code that is crashing has been traversed hundreds of times and is linear with no exits.

The only possible hole I can find in reviewing the code is the clear() preceding the array load. Does the clear function act as one change and the group of adds as a second change? Is there a timing consideration? There are from 1 to 24 entries in the list, so the load should take milliseconds and not seconds…

I’m looking for ideas and clues. Please scan the code and see if you see a glaring error or side effect in the code. It is the only place the ListView’s associated array data is altered in the app. The background code only alters the hold array.

Please don’t enter a full code rewrite in an answer. I’m continuing to try and find the why and which. I don’t want to waste more than a few minutes of your time. I will look at this post often for the next few days and answer any questions I find. Thanks for any help…

———– Update to add code requested ———-

The code in onCreate is:

    setContentView(R.layout.fooddeslist);
    foodDescHeader = (TextView) findViewById(R.id.foodDescHeading);
    foodDescListView = (ListView) findViewById(R.id.foodDescList);
    foodDescArrayList = new ArrayList<HashMap<String, String>>();
    holdFoodDescArrayList = new ArrayList<HashMap<String, String>>();
    foodDescAdapter = new SimpleAdapter(this, foodDescArrayList,
            R.layout.longdescitem, new String[] { GC.FOODDESCLIST_LINE1,
                    GC.FOODDESCLIST_LINE2 },
            new int[] { R.id.longdescListItemLine1,
                    R.id.longdescListItemLine2 });
    foodDescListView.setAdapter(foodDescAdapter);
    registerForContextMenu(foodDescListView);

The array entries are:

    listEntry = new HashMap<String, String>();

The hold array is a duplicate of the adapter’s array. The hold array is loaded in the doInBackground function in the AsyncTask. I’d show the background code, but it’s about 500 lines of code. The end result is that the hold array is loaded with the 2 lines to display and ancillary data that is unique to each entry. Row ids for various bits of data in other tables that is used when an entry is selected. The duplicate tables allow me to take eons (to gigahertz processors) loading the array. The transfer in the UI running post execute just takes a couple of milliseconds.

longdescitem.xml is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical">

     <TextView android:id="@+id/longdescListItemLine1"
        android:textStyle="italic"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#ff9900"
        />
     <TextView android:id="@+id/longdescListItemLine2"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:textColor="#b89300"

         />
</LinearLayout>

R.layout.fooddesclist is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/foodDescHeading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="2dip"
        android:text="Page 1 of 10 (nnn entries)"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#b89300" />

    <ImageButton
        android:id="@+id/foodDescForward"
        android:layout_width="50px"
        android:layout_height="50px"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="12dip"
        android:layout_marginTop="5dip"
        android:background="@drawable/forward"
        android:clickable="true"
        android:onClick="foodDescForwardClicked" />

    <ImageButton
        android:id="@+id/foodDescBack"
        android:layout_width="50px"
        android:layout_height="50px"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="12dip"
        android:layout_marginTop="5dip"
        android:background="@drawable/back"
        android:clickable="true"
        android:onClick="foodDescBackClicked" />

    <View
        android:id="@+id/foodDescSpacer1"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/foodDescForward"
        android:layout_marginBottom="2dip"
        android:layout_marginTop="2dip"
        android:background="@drawable/divider" />

    <ListView
        android:id="@+id/foodDescList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/foodDescSpacer1"
        android:layout_marginLeft="2dip"
        android:layout_marginRight="2dip"
        android:cacheColorHint="#00000000"
        android:divider="#b89300"
        android:dividerHeight="1.0px" />

</RelativeLayout>

——– Another Update ————–

I’ve added some code to the opPostExecute function.

    protected void onPostExecute(String result) {
        MyLog.d(TAG, "onPostExecute");
        foodDescArrayList.clear();
        foodDescAdapter.notifyDataSetChanged();
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            MyLog.d(TAG, "Sleep failed: " + e.getMessage());
        }
        int entries = holdFoodDescArrayList.size();
        HashMap<String, String> listEntry;
        for (int i = 0; i < entries; i++) {
            listEntry = new HashMap<String, String>();
            listEntry = holdFoodDescArrayList.get(i);
            foodDescArrayList.add(listEntry);
        }
        holdFoodDescArrayList.clear();
        hideProgress();
        foodDescAdapter.notifyDataSetChanged();
        String ents = " entries";
        if (rowsReturned == 1) {
            ents = " entry";
        }
        foodDescHeader.setText("Page " + Integer.toString(currentPage + 1)
                + " of " + Integer.toString(pageCount) + " (" + Integer.toString(rowsReturned) + ents + ")");
        loadActive = false;
    }

After two hours of steady testing on the Atrix, it hasn’t crashed yet. Before the code, I would get a crash at least once and sometimes twice in 2 hours. I added the notifydatasetchanged after the clear and followed it with a 300 msec sleep. I think the operating system was stepping on its toes because the original notify got lost. Although the database queries can take up to 8 seconds, most of the time it’s instant answer. The progress dialog never had a chance to fully set up. The screen would flicker and then the listview would show. The progress display was never identifiable. (The progress dialog is turned on in the preExecute function.) The entire AsyncTask was completing in less than 300 milliseconds. Maybe this is a fix and maybe not.

  • 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-28T00:13:44+00:00Added an answer on May 28, 2026 at 12:13 am

    I’m answering this myself to close the post as answered.

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

Sidebar

Related Questions

I have built an app that works only when not run as a Windows
This is probably a setting error somewhere. I have a django app that works
I have an App that downloads and displays images from URL's. This works fine
Story: One of the app that i have works on python 2.4 and other
I have an MVC3/EF4.1 app that I'm building which now works fine on my
i have a very small utilty app written in c# that works fine on
I have downloaded the Websphere 2.1 App Server and verified that it works fine.
have an app that finds your GPS location successfully, but I need to be
I have small problem. When I launch my app in emulator it works just
I have developed an android app that mainly targets smartphones. However in tablet emulator

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.