Wednesday, October 12, 2011

[android-developers] Re: SQLite slow

Don't use getters/setters. Abstract your model's interface at a
higher level so that your updates can be bracketed.

On Oct 13, 4:29 am, John Goche <johngoch...@googlemail.com> wrote:
> On Wed, Oct 12, 2011 at 5:38 PM, Christopher Van Kirk <
>
> christopher.vank...@gmail.com> wrote:
> >  You haven't provided enough information to help you.
>
> > The question you need to ask is why is it slow? Are you opening and closing
> > the connection many time? Too many records? Complex joins? Inefficient
> > query? Lack of indexing? Unintentionally cartesianing?
>
> I don't have a lot of data. Just the following class accessed from every
> activity in my application and the storeAndRetrieve method called (which
> calls insert and delete sql statements on a handful of tables each having
> around just 60 rows each at the moment).
>
> class DB {
>
>   private DB(Context ctx) {
>
>     dbHelper = new DBHelper(ctx);
>     database = dbHelper.getWritableDatabase();
>
>   }
>
>   public static DB db(Context ctx) {
>     if (db == null)
>       db = new DB(ctx);
>     return db;
>   }
>
>   // store and retrieve data
>
>   public Data storeAndRetrieve(Data data) {
>
>     putData(data);
>
>     Data retData = getData();
>
>     return retData;
>
>   }
>
>  // ... data getters and setters
>
>   private static DB db = null;
>   private DBHelper dbHelper;
>   private SQLiteDatabase database;
>
> }
>
> Yes when I run sqlite3 from adb shell it is fast, but for some
> reason when an activity is pushed and reads the data once
> opened it takes more than half a second which really slows
> down the user experience.
>
> Thanks for your help,
>
> John Goche

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment