Android :: Android - Use One SQLiteOpenHelper Class For Multiple Database Files

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.

Android :: Android - use one SQLiteOpenHelper class for multiple database files


Android :: Calling GetSharedPreferences(); From SQLiteOpenHelper Class?

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

Android :: SQLiteOpenHelper Existing Database?

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

Android :: Database In Application - SQLiteOpenHelper GetType?

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

Android :: Full Android Database Class For Existing SQLite Database?

Aug 23, 2010

I'm trying to deploy an application with an existing SQLite database.I've been reading though the examples that are posted but they are always missing some part of the class. I feel like I'm trying to bake muffins but no one told me to use baking powder.Can someone post a full database helper class for depoying an SQLite database on Android? Edit : Delete old code because it doesn't work.

View 2 Replies View Related

Android :: Static Database Class To Use With Any Activity

Jan 5, 2010

I am new to Android, and I haven't developed any app regarding databases on Android yet. So I have a few basic questions. I am after a good database class sample, that will let me to run the CRUD operations. I would like to use it as a static class

like: clsDB->Select("select * from clients");
or objClient->Delete(clientid);

I am wondering if someone, can share his database classes, if more people share the best. Also I have in mind to reuse this class in multiple ways, I will have services, activities etc...

View 4 Replies View Related

Android :: Utility Class For Database Query

Sep 23, 2009

Can anybody suggest what functionality to provide in a query utility class/classes? The idea is to provide a database utility package for android developers. I just wanna do it for android community and of course for my learning.:-)

View 5 Replies View Related

Android :: How To Import Cursor From Database Class Into Current One?

Jul 1, 2010

Here is my code for my db class:
package one.two;
import java.util.List;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import java.util.ArrayList;
public class DBAdapter extends ListActivity
{public String status = "status";
public String id = "id";
public String arrival = "arrival";
public String destination = "destination";
public String ferry = "ferry";
private static String DB_PATH = "/data/data/one.two/databases/";
private static final String DATABASE_NAME = "ferry.db";
private static final String DATABASE_TABLE = "port";
public static Context context;
public Cursor c;
public static SQLiteDatabase DbLib;
//overloaded non-null constructor
public DBAdapter(Context context) {
DbLib = context.openOrCreateDatabase(DATABASE_NAME,
SQLiteDatabase.CREATE_IF_NECESSARY,null);
System.out.println("OpenOrCreateDB Done");
} public class DatabaseHelper extends SQLiteOpenHelper {
Context context;
DatabaseHelper(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context = context;
}//end constructor DatabaseHelper
// ---closes the database---
public void close() {
DBHelper.close();
}//end close()
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion){
}//end onUpgrade()
@Override
public void onCreate(SQLiteDatabase db){
}//end onCreate()
}// end class DatabaseHelper
private static DatabaseHelper DBHelper;
private static final int DATABASE_VERSION = 1;
public static ArrayList<String> getAllTitles(){
ArrayList<String> port = new ArrayList<String>();
Cursor c=null;
c = DbLib.query("port"
new String[] { "status", "id", "arrival",
"destination", "ferry" }, null, null,
null, null, null);
try {
if (c!=null) { // start - when there is at least 1 record
System.out.println("Cursor is NOT NULL");
int i =0;
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
{// Debug Stm
System.out.println("Record No. "+i);
System.out.println(c.getString(0));
System.out.println(c.getString(1));
System.out.println(c.getString(2));
System.out.println(c.getString(3));
System.out.println(c.getString(4));
// Assign database cursor.records to arraylist
port.add(i,c.getString(0));
port.add(i,c.getString(1));
port.add(i,c.getString(2));
port.add(i,c.getString(3));
port.add(i,c.getString(4));
i = i + 1;
} } // end - where there is at least 1 record
} finally {
if (c!=null) {
c.close();
} } return port;
}//end getAllTitles()
public void open() {
//Open the database
String myPath = DB_PATH + DATABASE_NAME;
DbLib = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
} }//end class DBAdapter
My Arrival class
package one.two;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class Arrival extends ListActivity
{ private ListView listView;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{ ArrayList<String> retList = new ArrayList<String>();
System.out.println("Start onCreate Function");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println("In onCreate Function");
System.out.println("In of GetData");
DBAdapter db = new DBAdapter(this);
System.out.println("DB Open");
db.open();
System.out.println("DB Opened");
retList = getData();
System.out.println("Out of GetData");
// force count no. of records in table
// dump to check index
int cnt = 2;
int i=0;
for (i = 0; i<cnt; i++)
System.out.println(retList.toString());
listView = (ListView) findViewById(android.R.id.list);
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, android.R.id.list, null, null, null);
this.setListAdapter(mAdapter);
// db.close();
} @SuppressWarnings("static-access")
public static ArrayList<String> getData()
{ ArrayList<String> items = DBAdapter.getAllTitles();
// titles ???? redundant
//ArrayList<String> titles = new ArrayList<String>(items);
System.out.println("Return a LIST titles");
return items;
} }

View 1 Replies View Related

Android :: Cannot Open Database In Service Layer Class

Sep 15, 2010

When I create a instance of the SQLiteOpenHelper, I always need a "Context" to be passed as its constructor's argument. To use this "Context", in my service layer class, I extends Activity class, though I do not display this activity on the screen because it is my service layer. I always get NullPointer exception when I open the SQLiteOpenHelper in my service layer class, Is it because my service layer class extends the Activity class but I did not show this activity on mobile screen? (That's there is no intent to my service layer class), if it is so, how to get rid of it if I wanna open a SQLiteOpenHelper in my service layer class which do not need to extends Activity, but need a Context object to pass to SQLiteOpenHelper?

View 2 Replies View Related

Android :: Multiple Versions Of Same Class File For Different SDK Targets?

Nov 5, 2009

This is for an Android application but I'm broadening the question to Java as I don't know how this is usually implemented. Assuming you have a project that targets a specific SDK version. A new release of the SDK is backward incompatible and requires changing three lines in one class. How is this managed in Java without duplicating any code(or by duplicating the least amount)?

I don't want to create two projects for only 3 lines that are different. What I'm trying to achieve in the end is a single executable that'll work for both versions. In C/C++, you'd have a #define based on the version. How do I achieve the same thing in Java?

View 5 Replies View Related

Android :: Dynamic Class Loading To Target Multiple Versions

Aug 20, 2010

I would like to make a single Android app for multiple Android versions (possibly every one of them)
My problem is that I want to check what is the version of Android the app is currently running on, and dynamically load a class which is version dependent. This part should be ok.

I just wonder how I can achieve that without compilation errors in my Eclipse project. I mean, the project is configured for a particular target (1.5, 2.1 ...), so if a class in my project is not compatible wich the selected target, it will result in errors.

Is there a way to export this classes even if they are not fit for the platform (I thought about a separated lib, but then again : how to compile theses classes into a lib without compilation pbs?) ? This should be ok since they won't be loaded until I ask them to after having checked Android version.

View 2 Replies View Related

Android :: Multiple Successive Queries To A Database

Apr 10, 2009

Has anyone other than me needed to make consecutive queries to a sqlitedatabase? My application works sometimes but other times (about 98% of the time), the app will crash. What I'm doing is using the sqlitedatabase.query(..) to return a cursor which I parse, I make multiple successive queries to the database and parse different recordsets/cursors.

My question would be does a sqlitedatabase need to recover or clean up after a .query is issued?

View 6 Replies View Related

Android :: Using Same Sqlite Database From Multiple Activities And Services

Apr 27, 2010

I have been trying to find a discussion on the best way to handle a common sqlite database which is shared by multiple Activities (or multiple Activities and Services). This is all in the same application.

It seems that if each Activity has:

CODE:.........................

View 14 Replies View Related

Android :: Share SQLite Database Across Multiple Activities?

Jul 20, 2010

I am developing an app which requires me to write to an SQLiteDatabase in one activity and access it from another activity . I am facing a problem implementing this. Any suggestions/ideas as to how we can share the database across multiple activities?

View 2 Replies View Related

Android : Creating Multiple Tables In A Single Database?

Feb 22, 2010

How to create two or more tables in one database in single class which extends sqliteopenhelper in one function oncreate.

View 2 Replies View Related

Android :: How To Include Non Class Files In APK?

Jul 7, 2010

More specifically, have the files show up: /data/data/com.mydomain.foo/media/foo.js
Is this something I would have to provision programatically at runtime?

View 5 Replies View Related

Android :: Can Run Java Class Files

Jul 9, 2009

There are a lot of language which compiles into Java class files when can run on JVM (e.g. JRuby, Scala, Rhino). Can you please tell me if I can take those class files (compiles by the JRuby/Scala/Rhion compiler) and run it on Android platform?

View 2 Replies View Related

Android :: Eclipse Project - No Class Files Specified

Feb 19, 2009

I've noticed that then I use "clean" from Eclipse project menu on my project I receive following error
[2009-02-19 09:55:02 - MyListView] no classfiles specified [2009-02-19 09:55:02 - MyListView] Conversion to Dalvik format failed with error 1

Project doesn't use any external jars and rather simple. If I uncheck build automatically and build it - it builds and runs just fine. I'm on MacOSX 10.5.6 and JDK 1.6.0_07. And latest android SDK ( android-sdk-mac_x86-1.1_r1.zip 79046151 bytes becf0f1763d61eedce15d2a903d6c1dd )

View 2 Replies View Related

Android :: How To Exclude R.class Files From A Proguard Build

May 21, 2010

I am one step away from making the method described here: http://stackoverflow.com/questions/2761443/targeting-android-with-scala-2-8-trunk-builds work with a single project (vs one project for scala and one for android).

View 1 Replies View Related

Android :: Where Are Database Files Stored

Jul 9, 2009

I created a SQLite database on Android device. The program can read/write to database so the database file has obviously been created. The SQLiteDatabase.mPath is set to

db.mPath = "/data/data/dev.client.android/databases/clientDB.db"

but when I browse the directories on the device I can't locate the file clientDB.db. I looked inside data directory but it appears to be empty.Does anyone know what could be wrong here?

View 2 Replies View Related

Android :: Reading Database Files In 2.1

Oct 22, 2010

Is it possible to read the database files in Android 2.1 ? For example, files in /data/data/com.android.providers.contacts/databases/ contacts2.db. If yes, how? And is it possible to replace this file programmatically in order to import / export contacts or any other database files?

View 2 Replies View Related

Android :: How To See Database Files From Phone

Jul 21, 2010

I want to see the database files of my phone is it possible?

View 5 Replies View Related

Android :: Android - Accessing Single Database From Multiple Activities In Application

Dec 15, 2009

I have a todo list type application that stores all of the note data in a sqlite3 database. Each activity in the application needs access to the database to edit different parts of the data in real time.

Currently, I have each activity open its own DBManager object (the helper class I created to manage the database). This is causing problems though and I would like a slightly more global access solution so I don't have to keep opening/closing/creating a database.

I'm considering several options, and would like to hear pros and cons of each as well as other suggestions.

Singleton style. Have a wrapper class that returns a reference to the only database manager so any activity that needs it can use it.

Static Manager. Have the manager class be entirely static members and have it open the database on load. Easily accessible by anyone that needs it (which is everyone).

Merger between 1 and 2. I could make a database manager class that initializes the member singleton instance of the database and all of the data manipulation methods were static. Then I wouldn't even need a reference to the singleton to access the database.

View 3 Replies View Related

Android :: Sharing Sqlite Database Between Multiple Android Activities

Oct 12, 2009

Can two or more Android Activities open an sqlite3 database for write?

I have two Activities that need to insert data into the same sqlite database. When the second Activity calls SQLiteOpenHelper.getWriteableDatabase() an IllegalStateException is thrown with the message "SQLiteDatabase created and never closed".

I've been able to avoid the Exception by making my database object a singleton but I'm thinking there must be a better way.

View 2 Replies View Related

Android :: Android ContentProvider Database Query Multiple Tables

May 7, 2010

I'm writing an RSS reader for Android. I've faced a certain difficulty which the problem I can't resolve since databases aren't my expertise.. So i figured out maybe one of you could help me out! I currently have 3 tables (Categories, links and feeds). My goal is too link a feed to multiple categories. Therefor I'm using a Link table. My databases is an Android ContentProvider (sqlite) and looks like the following:

| Categories | | Links | | Feeds |
|------------| |---------| |-------|
| _ID | | Category| | _ID |
| Title | | Feed | | Title |
| URL |

I currently wrote the following code in my FeedListActivity to retrieve a list of links and their feeds.

CODE:.................

Now my question:

I was wondering how I could optimize this database layout, code or query so I would get my entries in a more efficient way. Because i believe this link table or the query to retrieve links isn't needed! Or am i doing this the correct way?

View 2 Replies View Related

Android :: Android - Inserting - Updating Multiple Records To SQL Database

Jun 24, 2010

I've just started working with SQL and Android and from what I can see, updates and inserts back to the database need to be handled individually?

I can retrieve a Cursor containing multiple records, but if I wanted to apply an update to each record in the cursor, I can only see how to do this individually, using ContentValues and Update(), and then the cursor requires reloading??

Same with if I wish to create multiple new records, these appear to be required to be inserted individually? Can I not create a List and bulk insert?

To me this seems slow and cumbersome, and there has to be something I'm not yet aware of (searching for answers is failing me... likely due to using incorrect terms being new to android/java)

Here's a very simple example of what I basically what I want to achieve, however there must be a better way to achieve this functionality. (I know there are some other bad practises in here, just creating a quick eample)

CODE:.........................

View 1 Replies View Related

Android :: Multiple-choice List From The Sqlite Database In Android

Jan 23, 2010

I'm new to Android programming, and I wanted to pull list options from a column of the SQLite database for the user to select. How would I go about doing this? Like, say the database table to be read is called countries, and the columns were ID, country, and capital. How would I let the user pick from the list of capitals and have the application return the information in that row?

View 1 Replies View Related

Android :: Best Way To Bundles Photos With App: Files Or In Sqlite Database?

Jun 7, 2010

Lets say that I have an app that lets you browse through a listing of cars found in a Sqlite database. When you click on a car in the listing, it'll open up a view with the description of the car and a photo of the car.My question is: should I keep the photo in the database as a binary data column in the row for this specific car, or should I have the photo somewhere in the resources directory? Which is better to do? Are there any limitations of Sqlite in terms of how big a binary data column can be?The database will be pretty much be read only and bundled with the app (so the user wouldn't be inserting any cars and their photos).

View 2 Replies View Related

Android :: All .class Files In My Java Application Loaded Into Memory After Appliaction Start?

Feb 3, 2010

I am making an app for Android, in my Activity I need to load an array of about 10000 strings. Loading it from database was slow, so I decided to put it directly into one .java file (as a private field). I have about 20 of these classes containing string arrays and my question is, are all the classes loaded into memory after my application is started? If so the Activity in which I need these strings would be loaded quickly, but the application as a whole would have a slow start...

Is there other way, how to very quickly load an 10000 string array from a file?

UPDATE:
Why I need these strings? My Android app allows you to find "journeys" in Prague's public transit - you choose departure stop, arrival stop and it finds your journey (have a look here). My app has a suggestions feature - you enter leter "c" as your departure stop and a suggestions ListView appears with stops starting with "c". For these suggestions I need the strings. Fetching the suggestions from database is slow (about 400ms on G1).

View 4 Replies View Related

Android :: Android - Specify Name Of Database To Be Created - On Using Multiple Databases

Aug 30, 2010

I'm thinking about creating an application that uses multiple databases. The user would be able to specify the name of the database to be created, and select which database to use from those existing in the /databases/ directory.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved