Android :: SQLiteOpenHelper Without Or Less Restrictive Use Of Context?
May 21, 2010
If you extend SQLiteOpenHelper, for the Constructor you have to use a Context. I am wondering if there is a way to leave this out, and be able to work with database tables without a Context.
Or at least be least restrictive, I mean a way of project/class structure that will make history the several context passings I have to do now.
As it is my application has several level of classes, chained in each other, and there are a few that connects to the database, but have no whatsoever influence on the interface, so they don't actually need the Context.
Are you creating your classes in the way that you pass each time a Context to them?
If not, how you do, how you reuse a Context in a short class?
View 1 Replies
Jul 21, 2010
Do I need an instance of my SQLiteOpenHelper class for each Activity I have? I have 1 currently that all activities access, but started getting an exception
"illegal state exception SQLiteDatabase created and never closed "
on simple a simple query and I can't seem to figure out why this is happening. I read online about this, and wanted to try to understand why the SQLiteOpenHelper was dependent on an Activity.
Is there a way to just have open SQLiteDatabase object without the Helper and have it just exist within all activities?
View 10 Replies
View Related
Sep 10, 2009
I get a SQLiteException if I try to issue an alter statement in the onUpgrade method of SQLiteOpenHelper subclass:
Can't upgrade read-only database from version X to Y: /path/to/db
That makes no sense at all! Where did I go wrong?
View 5 Replies
View Related
Feb 11, 2010
I would like to know if it is possible to have several DbOpenHelper in the same app Android but to use them to write and read in the same database? because I'm trying to create tables from 2 different OpenHelper (with different names) and only the first one seems to create. when I try to run the 2nd one, i get an error...
View 1 Replies
View Related
Jun 9, 2010
I have a SQLite database, and several tables within that datbase. I am developing a DBAdapter for each table within the database. (reference Reto Meier's Professional Android 2 Application Development, Listing 7.1).
I am using the adb shell to interface with the database from the command line and see that the database is being populated as I expect. Occasionally, I want to drop a table so that I can ensure it's being built properly, from scratch.
The problem is that SQLiteOpenHelper only checks to see if the database exists. Is there a typical solution to writing a helper to also see that the table(s) exists? Basically once I drop a table, the helper checks to see that the database exists and assumes all is well.
Also, the CREATE_DATABASE string used in the reference above only creates the one table. Should I consider using the DBAdapter for an adapter to ALL of my tables? That doesn't seem as clean to me.
View 1 Replies
View Related
Aug 17, 2010
I am doing my first app with a database and I am having a little trouble understanding the onUpgrade function. My database has a table with an items and a favorite column so that the user can favorite an item. Most implementations I see simply drop the table and reconstruct it but I don't want to do this. I want to be able to add more items to the table.
When the app is upgraded through the android marketplace does the database know its version number? So could I increment the version number in the code and then export it to the marketplace and when the user boots up the upgraded version for the first time then onUpgrade will be called?
If this is the case my onUpgrade would simply pull from a file and add the database items in. Is this a standard way of doing things or is there a better way of handling this in Android. I am trying to stay as standard as possible.
View 1 Replies
View Related
Jul 9, 2010
The documentation does not make the interation between onUpgrade() and onCreate() clear.
When implementing onCreate() should this create the database at version 1, assuming that onUpgrade will apply all of the patches to bring it up to version x (lets say version 5 for example)? Or should onCreate build the latest version of the database, and onUpgrade is only used to upgrade legacy clients.
I kind of prefer the first, because it effectively means that the same SQL is executed for everybody. Whereas the second options means that there is a potential for onCreate to build something slightly different to the succession of patches built by onUpgrade.
I can always make onCreate call into onUpgrade, however, this is the kind of implementation detail that should go into the javadocs...
View 3 Replies
View Related
Jun 11, 2010
The documentation describes the class as a helper object to create, open, and/or manage a database. Having that in mind wouldn't you say that the name is a little misleading?
View 2 Replies
View Related
Sep 13, 2010
Every time i increase my database version and push the upgraded app to the users, something weird happens.. For some it works perfectly fine, and some report crashes (including through the Market's reporting system) caused by the lack of table columns i just added in onUpgrade.
If you want to see the method:
http://code.google.com/p/tag-todo-list/source/browse/trunk/Donut/src/com/android/todo/data/ToDoDB.java#136
I can't spot any exceptions that appear in onUpgrade. What i'm currently doing to bypass these problems is intercepting the exceptions where the new fields are invoked for the first time and then calling onUpgrade 'manually', which is kind of dirty.
Also, the app sometimes generates a 'no such table' SQLiteException when accessing the main table (again, only for some users) which is incredibly strange... Does someone know why these things happen? Or can you spot something wrong in my code?
View 1 Replies
View Related
Jun 9, 2010
I have an existing SQLite database file from another project.
Where do I include the database file into my Eclipse project to have it deploy with the app.
Do I need to indicate that the database file is writable? (In the iPhone world you need to copy the database file from the app's bundle to a writable folder on the iPhone proper before first use.)
Once I have the database file on the phone, how do I tell SQLiteOpenHelper to use it? (I extend SQLiteOpenHelper in a custom class.
View 1 Replies
View Related
Oct 17, 2010
How can I emulate an onUpgrade call for my SQLiteOpenHelper class? I have tried changing the version number in my SQLiteOpenHelper class and versionCode in manifest but onUpgrade is not called. Any idea? I need to check my onUpgrade code before upload it to the market, I don't want my app's users get a buggy upgrade.
View 10 Replies
View Related
Aug 24, 2010
I'm trying to implement a database in my application. I'm following a tutorial about writing my own ContentProvider, but I'm confused about SQLiteOpenHelper::getType. We're supposed to write it and, essentially, write a switch that returns the MIME type corresponding to the type of data we're dealing with.
I don't fully understand it. I'm not sure, even though I have an example, what is precisely supposed to be conveyed here. How do I determine the MIME type of my different tables of data?
View 1 Replies
View Related
Feb 27, 2010
I have two classes, one MainClass and one DataBaseHelper class, which extends SQLiteOpenHelper.
From my MainClass I call a method in the DataBaseHelper class to open a data base. Before opening the data base I want to check the users data base version (this is important as soon as I want to update the data base and push it to the Android market). So from the DataBaseHelper class I call the following method, which is in the MainClass.
CODE:..........
I call the checkCurrentDbVersion() method from the DataBaseHelper class like so:
CODE:.....................
As soon as the debugger runs the following line, it stops.
CODE:...........
I have no constructor defined. Could that be the failure?
View 2 Replies
View Related
Nov 16, 2009
I've had fine luck using SQLite with straight, direct SQL in Android, but this is the first time I'm wrapping a DB in a ContentProvider. I keep getting a null pointer exception when calling getWritableDatabase() or getReadableDatabase().
Is this just a stupid mistake I've made with initializations in my code or is there a bigger issue?
CODE:.........
But here's LogCat showing the exception:
View 2 Replies
View Related
Jan 21, 2010
How can I launch a contextmenu from a contextmenu? I'm trying to replicate the MediaPlayer action that happens when you long click a song, then click "Add to playlist" in the resulting contextmenu. When you click that menu item, another contextmenu pops up with "Add to playlist" as the title, and "Current playlist", "New", and however-many-playlists-you-have defined after that.
View 4 Replies
View Related
Nov 20, 2010
My app uses two databases (separate files). To handle these databases I have created two Helper classes which extend SQLiteOpenHelper, one for each database.
I am now going to add a third database and wonder whether I need to create yet another Helper class (and if I used a 4th and a 5th database would I need even more Helper classes), or can I use the same Helper class for multiple databases?
The problem that I see with trying to use just one Helper class is that I can't see how to pass the name of the individual database files to the Helper. At present the name of the database is hard-coded as a Static field of each of the Helper classes, but if I had only one Helper class I would need to be able to pass the different names in to the Constructor when creating the separate Helper objects; the problem is that the SQLiteOpenHelper Constructor seems to be called by Android with just one parameter: the Context.
View 2 Replies
View Related
Jul 19, 2010
I'm confused about the concept of the Context class. I see that it's a base class of Activity, but the Android docs also mentions the Context storing global information about the app environment. So in my app which has 3 activities, does that mean I have 3 distinct Context objects, or do they actually refer to 1 entity? Also, what is the lifetime of a Context object- does it live until the last component of this activity's process is garbage collected?
View 1 Replies
View Related
Nov 24, 2010
i have got a stupid question to ask. I created a custom ContextMenu. But when i call the menu, the menu displayed will also have the default menu added in. Is there anyway for the default ContextMenu not to appear as well?Code requested: @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
menu.setHeaderTitle("Recipients");
inflater.inflate(R.menu.menu_contacts, menu);
View 1 Replies
View Related
Jan 4, 2010
Is there a way to get the current Context instance by using a static method? I'm looking for that way because i hate saving the context instance each time it changes.
View 1 Replies
View Related
May 15, 2009
When you are developing on an application level(Services, Activities) you always get this Context reference automatically. But what if I am on a lower level and developing a program started with app_process, how can I get hold of a Context then? Its a huge part of the API that need this context. What the proper way to create a Context instance?
View 7 Replies
View Related
Jun 12, 2009
In an Android app, is there anything wrong with the following approach..
View 4 Replies
View Related
Oct 10, 2010
I often run into the following dilemma: I need some singleton-like object in my app (typically some central manager-like thing) and this object needs a context for various things. This means that I either have to pass a context to all methods needing one or have some sort of init-pattern to the object. Neither is pretty I think. What is the correct way of doing this? Or is this simply (even the definition of) a Service?
View 15 Replies
View Related
May 3, 2010
I'm considering creating a singleton wrapper for a Context so my model objects, if necessary, can open and read from a database connection. My model objects do not have access to a Context, and I'd like to avoid needing to pass a reference to a Context from object to object.I was planning to place into this singleton a reference to the Context returned by Application.getApplicationContext(). This singleton object would be initialized in my custom Application instance before anything else would need to or have a chance to use it.Can anyone think of a reason to not do this?
View 3 Replies
View Related
Jul 19, 2010
What is the lifetime of an app's global android.content.Context object? Does it last until the last component of the app is terminated by the Android runtime?
View 2 Replies
View Related
Jun 18, 2009
Hi! I use dialog with multipleChoiseItems. Is there any way to create context menu for list of the items?
View 2 Replies
View Related
Apr 20, 2010
I have a ListView with a ContextMenu, it has one CheckBox (the CheckBox has android:focusable="false") and one TextView per row, but you can hide the TextView in the preferences menu. After doing that, the CheckBox wasn't registering the ContextMenu, so of course, why not register For Context Menu(cb) and unregisterForContextMenu(getListView())? Yes, i did that, but then, when when i call the delete command of onContextItemSelected, the app crashs. AdapterContextMenuInfo info=(AdapterContextMenuInfo)item.getMenuInfo(); db.deletarTarefa(info.id);
View 1 Replies
View Related
Aug 30, 2010
So I'm working on a service that will handle requests to send data to a socket.I've done socket programming in a service before, but only within the same application. I'd like this to just sit and do nothing until any application wants to give it data to send. That's all well and good.I have register an intent filter and the usual stuff and can process the data. But I want to process the data coming from different activities in different threads (subsequent calls from the same application will be computed on the same thread).Is there a way to get the calling package or app or whatever? I'd prefer not to require passing in an identifier as an extra to prevent spoofing. (It's not a serious security concern, it's just each application needs its data processed in the order that it's received.)
View 1 Replies
View Related
Mar 7, 2010
I have a context menu option that, when clicked, will load some information from the web and insert it into a database.So this is a lengthy process and I would like to display a progressdialog over the top of the context menu when this option is selected.I've got the progressdialog running now, but it won't show up.It's almost like the context menu is covering it.So is there a way that I could get the progressdialog to show up on top of the context menu and be visible to the user.
View 2 Replies
View Related
Nov 8, 2010
I have created one music app. In this app, i have loaded albums dynamically by using URL request and displayed as table layout. For each table row i registered context menu. But when the context menu is appeared by long press on each table row i could not find on which table row the context menu is appeared. If anyone know please guide me to solve this problem.
View 2 Replies
View Related
Dec 10, 2009
I have a ListView with 5 items. Each of the items can be long pressed to open a Context Menu. The Menu has 5 options and I want them to be selectable, by having a check box. I know of the multiple choice listview but was not sure how to have this checkbox feature in a ContextMenu.Does anyone know if this is possible and if so, how?
View 4 Replies
View Related