1. Download our Official Android App: Forums for Android!

Apps sqlite storage

Discussion in 'Android Development' started by piller187, Jun 19, 2011.

  1. piller187

    piller187 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    10
    Joined:
    Jun 18, 2011

    Jun 18, 2011
    10
    0
    15
    I've used sqlite in a Windows C/C++ environment before so I'm familiar with it but new to using it in the Android environment. Looking at some tutorials like Android SQLite Basics: creating and using a database, and working with sqlite3 | Screaming Penguin on how to use it and it seems pretty straight forward.

    A question I have is that this creates a DB inside the OnCreate method of the activity which seems fine for the first run of the application, but I assume we should first see if the DB is already created before doing such a thing? What's the general practice around that? Is there maybe a way to make the DB get created on install of the application so the application itself when running will always have the DB?
     

    Advertisement

  2. PGP_Protector

    PGP_Protector Well-Known Member
    Rank:
    None
    Points:
    43
    Posts:
    174
    Joined:
    Aug 3, 2010

    Aug 3, 2010
    174
    38
    43
    Haven't done any Android Programming (yet) but for my C# apps using SQLite, I first attempt to Open the DB via a Try method, if not found, I then Create it.

    You should be able to do something similar on the Android.
    First try to Open it, if it's not found, create it.
     
  3. piller187

    piller187 Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    10
    Joined:
    Jun 18, 2011

    Jun 18, 2011
    10
    0
    15
    Yeah I would think so too but every article I read about it doesn't do that. They derive from some sql class and override OnCreate method from it to create the DB. Then in their activity code they make an object of this derived class. In these examples they aren't doing anything like you said or like I'd expect so just wondering if this OnCreate from this derived sql class is doing something like that behind the scenes or something.

    YOu don't really Open it directly, instead you call
    getWritableDatabase

    From your derived SQLLite class. It's a strange and new world over here in Java/Google land :)
     
  4. alostpacket

    alostpacket Over Macho Grande?
    Rank:
    None
    Points:
    513
    Posts:
    7,972
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,972
    3,603
    513
    Android App Developer
    NY
    Oh you aint seen nothing yet! :)


    (as for your question you basically understand what's going on so nothing to add there :) )
     

Share This Page

Loading...