Filling a large database causes crash

by NFSpeedypur » Tue, 10 Mar 2009 11:00:25 GMT


Sponsored Links
 I am trying to on first start up fill up a sql database with the
default values.  This database is around 9000 entries and it is
causing the app to go over the 16MB heap.  I am trying to find a way
to do this so that it will not cause this over flow.

At the moment I am running the 9000 inserts, 1 after another in a
thread.  Are there any other suggestions?



--~--~---------~--~----~------------~-------~--~----~



Filling a large database causes crash

by Mark Murphy » Tue, 10 Mar 2009 21:19:35 GMT


 


Use transactions. The heap problem is probably due to SQLite holding
everything in transaction buffers. You might, say, do a transaction for
every 100 entries or so.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Filling a large database causes crash

by NFSpeedypur » Thu, 12 Mar 2009 00:20:09 GMT


 I changed this to loading the database in from an asset and it works
fine.  But the issue is now the loading time.  On the emulator it
takes over 5 seconds for the list to be populated.  And when doing a a
filter (getListView().setTextFilterEnabled(true);) it takes almost 10
seconds to filter the list.  Is it unreasonable to think that about
9000 entries should be sorted faster?

Mark,

Does your book talk about handling this type of stuff?  I see that
version 2.0 is not in print so I plan to pick it up.

David





--~--~---------~--~----~------------~-------~--~----~



Filling a large database causes crash

by Mark Murphy » Thu, 12 Mar 2009 00:37:40 GMT


 


That feels wrong, but I haven't tried a 9,000-row table.


Did you add an index on the to-be-filtered columns?


There's some coverage of this in the _Advanced Android_ book (not yet in
print, beta available to subscribers), with more to come as that book
gets expanded over the course of the next 12-18 months.


Version 2.0 is available in print. If you're looking at the Amazon page,
they *still* have not updated the cover (grrrrrrrrr) -- I'll be trying
to do that again later this week.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!

--~--~---------~--~----~------------~-------~--~----~



Filling a large database causes crash

by NFSpeedypur » Thu, 12 Mar 2009 01:08:42 GMT


 No I did not add any index to the to be filtered columns, I am using a
basic array so I did not know there could be a index?

setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, Titles));

Maybe it will be worth grabbing the subscription on Commonwares
instead of the book.  If I download the pdfs, am I able to print pages
for personal use or is it only for computer viewing?

David





--~--~---------~--~----~------------~-------~--~----~



Filling a large database causes crash

by Mark Murphy » Thu, 12 Mar 2009 01:13:09 GMT


 


If the data is in a database, use a CursorAdapter or
SimpleCursorAdapter, rather than loading them all into an ArrayAdapter.
That should be significantly faster.


Printing is perfectly fine for personal use.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!

--~--~---------~--~----~------------~-------~--~----~



Filling a large database causes crash

by NFSpeedypur » Thu, 12 Mar 2009 01:19:51 GMT


 I believe I understand more of what you are saying about adding the
index.  Do you mean to the actual column in the database?  Does
filtering the text requery the database each time?

David







--~--~---------~--~----~------------~-------~--~----~



Filling a large database causes crash

by NFSpeedypur » Thu, 12 Mar 2009 01:21:53 GMT


 I see yes I had tried the cursor in the past and it does work faster,
but I could not get the Filter to work.  Do I need to write my own
search portion if I use the cursor method?

Thank you for your help.  You personally have been a lifesaver to me,
in the android field.

David






--~--~---------~--~----~------------~-------~--~----~



Filling a large database causes crash

by Mark Murphy » Thu, 12 Mar 2009 01:22:02 GMT


 


That I don't know -- I haven't tried filtering. My guess is yes, but
queries, particularly on indexed columns, should be pretty snappy.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!

--~--~---------~--~----~------------~-------~--~----~



Filling a large database causes crash

by Mark Murphy » Thu, 12 Mar 2009 01:24:25 GMT


 


Unfortunately, I don't know -- I haven't tried filters with cursors as
yet. There's just *so* many nooks and crannies to play around in! I'll
add that to my to-do list for a future edition of _Advanced Android_.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!

--~--~---------~--~----~------------~-------~--~----~



Filling a large database causes crash

by NFSpeedypur » Thu, 12 Mar 2009 01:25:47 GMT


 Alright well I will work on that and maybe send you an email if I can
find additional information about it.  I just purchased a commonswares
subscription and I look forward to reading your books.

David





--~--~---------~--~----~------------~-------~--~----~



Filling a large database causes crash

by Will » Sat, 14 Mar 2009 08:41:48 GMT


 You will need to write your own filter when filtering.  I have only
done it with a Cursor (SimpleCursorAdapter sepcifically).  Searching
the Developer group for AutoCompleteTextView should send you in the
right direction.






--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to set Parent ImageView Style

Hello,

i've just cant figure out why this should be wrong ?

<style name="Logo" parent="@android:style/Widget.ImageView">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">@dimen/title_height</item>
<item name="android:src">@drawable/mv_logo</item>
<item name="android:paddingLeft">5dp</item>
<item name="android:paddingRight">5dp</item>
</style>

Eclipse complain about the parent :error: Error retrieving parent for
item: No resource found that matches the given name '@android:style/
Widget.ImageView'.

Whats is different for an ImageView ?

Thx,
Jens


-- 

2. startMethodTracing() can't open trace files

I looked at the related posts, but my problem seems more basic. Full
path, or no path, file extension or not, I get a "Unable to open trace
file '/sdcard/traceit.trace': Permission denied" error when I run on
the emulator. Do I need to 'prepare' the emulated sd card?

import android.app.Activity;
import android.os.Bundle;
import android.os.Debug;

public class TraceItActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Debug.startMethodTracing("/sdcard/traceit");
        setContentView(R.layout.main);
        Debug.stopMethodTracing();
    }
}

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.hiplogic.traceit"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
       <uses-sdk
        android:minSdkVersion="5"
        android:targetSdkVersion="8" />
        <application android:icon="@drawable/icon"
android:label="@string/app_name">
        <activity android:name=".TraceItActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

-- 

3. Map API Key is not working generated through signup Certificate

4. Tutorial Upgrade Samsung Galaxy S CDMAakaFASCINATEfrom eclair to Froyo

5. appwidgets

6. Tutorial Upgrade Samsung Galaxy SCDMAakaFASCINATEfrom eclair to Froyo

7. Tanya inject flexi di htc evo