В соответствии с различными ответами здесь и в веб-расширении приложения, и унаследованный метод getDatabasePath() позволит установить путь хранения базы данных из стандартного места внутренней памяти на вставленную SD-карту большего размера.
Это не работает для меня. Предлагаемая конструкция по-прежнему использует базу данных во внутренней памяти. На самом деле метод getDatabasePath() никогда не вызывается SQLiteOpenHelper.
Я хотел бы запустить это.
Вот что я сделал до сих пор:
1.) Расширение приложения:
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();
}
}
2.) Добавление расширенного приложения в манифест:
<application
...
android:name="MyApplication"
... >
3.) Расширение и использование SQLiteOpenHelper:
public class MySqliteOpenHelper extends SQLiteOpenHelper {
public void onCreate(SQLiteDatabase sqliteDatabase) {
...
}
@Override
public void onUpgrade(SQLiteDatabase sqliteDatabase, int oldVersion, int newVersion) {
...
}
}
4.) Используя расширенный SQLiteOpenHelper в моих действиях обычным способом:
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();
}
}
Я хочу указать, что расширенный класс Application работает в целом. Я вижу это, потому что вызывается MyApplication.onCreate(). Но MyApplication.getDatabasePath() не вызывается.
Любая помощь приветствуется.