sqliteopenhelper

Android AsyncTask and SQLite DB instance

早过忘川 提交于 2019-12-29 13:34:12
问题 I have a problem and I am not sure how to approach it. An activity in my app has multiple AsyncTask s which access single SQLiteOpenHelper . I initialize and open the helper in onCreate() and I am closing it in onStop() . I also check if it has been initialized in onResume() . Since I have published my app I received number of errors with Null Exception in doInBackground where I try to access the DB helper. I know that this is happens because the DB is closed ( onStop() ) just before the

Android AsyncTask and SQLite DB instance

别等时光非礼了梦想. 提交于 2019-12-29 13:34:00
问题 I have a problem and I am not sure how to approach it. An activity in my app has multiple AsyncTask s which access single SQLiteOpenHelper . I initialize and open the helper in onCreate() and I am closing it in onStop() . I also check if it has been initialized in onResume() . Since I have published my app I received number of errors with Null Exception in doInBackground where I try to access the DB helper. I know that this is happens because the DB is closed ( onStop() ) just before the

Concurrent access to a SQLite database in Android - db already closed

点点圈 提交于 2019-12-29 05:36:07
问题 I read a lot of topics on this subjet but no one could answer my question. I access my database from concurrent threads, my SQLiteOpenHelper implements the design pattern of the singleton so I have only one instance for my app. I access my database with code like this : SQLiteDatabase db = DatabaseHelper.getInstance().getWritableDatabase(); ... Do some update in the DB ... db.close(); I don't understand why I still get "db already closed" error, shouldn't the getWritableDatabase() method lock

Android SQLiteException: Failed to change locale for db to 'en_US'

随声附和 提交于 2019-12-29 05:07:09
问题 I recently updated one of my (open-source) Android apps and my users are getting an exception that I can't replicate. The key parts are : android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5) and then Caused by: android.database.sqlite.SQLiteException: Failed to change locale for db '/data/data/com.airlocksoftware.hackernews/databases/hacker_news_cache.db' to 'en_US'. This is happening on devices with Android 2.3 - 4.2.1, and in multiple places within the app

Fetch data from existing sqlite database

旧街凉风 提交于 2019-12-25 00:35:31
问题 I am having an existing sqlite database. I am developing an android app and I want to connect it with this existing sqlite DataBase. Problem 1: I have already included the sqlite database in my project via "DDMS push database function" as per my instructor's advise. Now I want to fetch the data from database, do I need to use SQLiteOpenHelper. If yes, how to use it and what will be coded in onCreate(SQLiteDatabase db) function and onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)

SQLiteDatabase.openDatabase vs SQLiteOpenHelper.getReadableDatabase

天大地大妈咪最大 提交于 2019-12-23 09:08:34
问题 Is there any difference between these two methods? Both return an opened SQLiteDatabase. Both can create a database if one doesn't exist. SQLiteOpenHelper also has getWriteableDatabase when read/write is needed... Which method should I use and where? Based on sample code I've seen, I'm using SQLiteOpenHelper to create my database in the first place, but then calling SQLiteDatabase.openDatabase when I need to use the database. 回答1: The openDatabase() is more flexible allowing you to specify

Robolectric: running multiple tests fails

冷暖自知 提交于 2019-12-23 06:58:36
问题 I am trying to run multiple tests with Robolectric 3.0 + Gradle using SQLite (OpenHelper) as database. Running each single tests works fine, but starting the whole test suite always results in RuntimeException in the 2nd test. This is my test dummy, which does not work. @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, sdk = 21) public class Dummy { @Before public void setUp() throws Exception { // setup activity ... } @Test public void testA() throws

Is it really necessary to create SQLite tables every time the application starts?

試著忘記壹切 提交于 2019-12-21 02:42:13
问题 I've noticed in more than one SQLite tutorial that the table is recreated in the onCreate() event of the class that extends SQLiteOpenHelper . I've already created my SQLite database and tables outside the Android environment (Eclipse IDE) with the help of a Firefox add-in. The database tables reside in the expected spot: C:\aXX3&Space\Android\workspace\OnDemandAndAutomatic_Project\assets It seems bizarre to me that I would have to recreate them programmatically each time (obviously, they

Is it really necessary to create SQLite tables every time the application starts?

半世苍凉 提交于 2019-12-21 02:42:04
问题 I've noticed in more than one SQLite tutorial that the table is recreated in the onCreate() event of the class that extends SQLiteOpenHelper . I've already created my SQLite database and tables outside the Android environment (Eclipse IDE) with the help of a Firefox add-in. The database tables reside in the expected spot: C:\aXX3&Space\Android\workspace\OnDemandAndAutomatic_Project\assets It seems bizarre to me that I would have to recreate them programmatically each time (obviously, they

android passing variables from inside database class

蓝咒 提交于 2019-12-18 18:21:10
问题 I am trying to pass some values that i get from inside database(that extends sqliteOpenHelper ) to another class. However i am using a cursor to get the data from that database which giving null values to other activities. Here is my Database: it has default values inside it , inserted public class DatabaseMaster extends SQLiteOpenHelper { SQLiteDatabase db; private static final String LOG = "DatabaseHelper"; // Database Version private static final int DATABASE_VERSION = 1; // Database Name