Note that there are some explanatory texts on larger screens.

plurals
  1. POHow using SQLiteOpenHelper with database on sd-card?
    text
    copied!<p>According to various answers here and in the web extending Application and it's inherited method getDatabasePath() would allow to set the database storage path from the standard internal memory location to an inserted SD-card of bigger size.</p> <p>This is not working for me. The suggested construct is still using the database on internal memory. In fact the method getDatabasePath() is never called by SQLiteOpenHelper.</p> <p>I would like to get this up and running.</p> <p>Here's what I did so far:</p> <p>1.) Extending Application:</p> <pre><code>public class MyApplication extends Application { @Override public File getDatabasePath(String name) { // Just a test File file = super.getDatabasePath(name); return file; } @Override public void onCreate() { // Just a test super.onCreate(); } } </code></pre> <p>2.) Adding extended Application to the Manifest:</p> <pre><code>&lt;application ... android:name="MyApplication" ... &gt; </code></pre> <p>3.) Extending and using SQLiteOpenHelper:</p> <pre><code>public class MySqliteOpenHelper extends SQLiteOpenHelper { public void onCreate(SQLiteDatabase sqliteDatabase) { ... } @Override public void onUpgrade(SQLiteDatabase sqliteDatabase, int oldVersion, int newVersion) { ... } } </code></pre> <p>4.) Using the extended SQLiteOpenHelper in my Activities in the usual way:</p> <pre><code>public class MyActivity extends Activity { private MySqliteOpenHelper mySqliteOpenHelper; private SQLiteDatabase sqliteDatabase; @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); ... mySqliteOpenHelper = new MySqliteOpenHelper(getApplicationContext()); sqliteDatabase = mySqliteOpenHelper.getReadableDatabase(); ... } @Override protected void onDestroy() { if (mySqliteOpenHelper != null) { mySqliteOpenHelper.close(); mySqliteOpenHelper = null; } super.onDestroy(); } } </code></pre> <p>I want to point out that the extended Application class is working in general. I can see this because MyApplication.onCreate() is called. But MyApplication.getDatabasePath() is not called.</p> <p>Any help is highly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload