• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps sqlite storage

piller187

Newbie
Jun 18, 2011
10
0
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?
 
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?

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.
 
Upvote 0
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 :)
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones