我正在使用SQLLite for Android基於phonegap的應用程序。我面臨的問題是,只要應用程序處於打開狀態,我就能夠獲取存儲的任何數據local.db文件。 對於例如我有一個設置功能,用戶可以保存他/她的設置,並進入db.Now我面臨的問題是,我無法獲取用戶在應用程序關閉後保存的數據,只要應用程序處於打開狀態,我就可以獲取數據。 所以問題是數據庫不持久。任何人都可以告訴即使應用程序關閉時如何將數據存儲在內存中?使用Phonegap從Android的SQLLite數據庫填充數據
這是我mainActivity文件
public class Demo extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
super.loadUrl(Config.getStartUrl());
try {
String pName = this.getClass().getPackage().getName();
this.copy("Databases.db", "/data/data/" + pName + "/app_database/");
this.copy("0000000000000001.db", "/data/data/" + pName
+ "/app_database/file__0/");
} catch (IOException e) {
e.printStackTrace();
}
}
void copy(String file, String folder) throws IOException {
File CheckDirectory;
CheckDirectory = new File(folder);
if (!CheckDirectory.exists()) {
CheckDirectory.mkdir();
InputStream in = getApplicationContext().getAssets().open(file);
OutputStream out = new FileOutputStream(folder + file);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0)
out.write(buf, 0, len);
in.close();
out.close();
}
}
}
這些都是我給的權限: -
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
複製代碼移動到if條件由提到NigelK做了之後trick.But卸載後構建並創建一個新的版本給我以下錯誤: -
01-10 16:11:34.466: E/SQLiteLog(29253): (1) no such table: CacheGroups
01-10 16:11:34.466: D/WebKit(29253): ERROR:
01-10 16:11:34.466: D/WebKit(29253): Application Cache Storage: failed to execute statement "DELETE FROM CacheGroups" error "no such table: CacheGroups"
01-10 16:11:34.466: D/WebKit(29253): external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&)
01-10 16:11:34.466: E/SQLiteLog(29253): (1) no such table: Caches
01-10 16:11:34.466: D/WebKit(29253): ERROR:
01-10 16:11:34.466: D/WebKit(29253): Application Cache Storage: failed to execute statement "DELETE FROM Caches" error "no such table: Caches"
01-10 16:11:34.466: D/WebKit(29253): external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&)
01-10 16:11:34.466: E/SQLiteLog(29253): (1) no such table: Origins
01-10 16:11:34.466: D/WebKit(29253): ERROR:
01-10 16:11:34.466: D/WebKit(29253): Application Cache Storage: failed to execute statement "DELETE FROM Origins" error "no such table: Origins"
01-10 16:11:34.466: D/WebKit(29253): external/webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(558) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&)
01-10 16:11:34.476: E/SQLiteLog(29253): (1) no such table: DeletedCacheResources
有關如何解決此問題的任何想法?
是的複製代碼移動到if條件做了trick.Thanks很多:) –
NigelK:卸載以前的構建和創建一個新的構建現在向我顯示一個錯誤。這是我得到的錯誤: - E/SQLiteLog(26682):(1)沒有這樣的表:CacheGroups。任何想法我做錯了什麼? –
我用錯誤日誌更新了我的問題,請檢查並讓我知道我做錯了什麼。 –