简体   繁体   中英

How to put a database with data in SD card only once-when the application is installed

I have a database which contains data. How is it possible to put the database in SD card only once? i mean -while it is being installed?

And also want some pictures to be pushed too.

Help me out please.

You can try SharedPreferences

private static final String FIRST_RUN = "first_run";
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences();

//Assume true if the key does not yet exist
if (prefs.getBoolean(FIRST_RUN, true)) {

    //Do your database operations
    ..............................................
} else {
    SharedPreferences.Editor edit = prefs.edit();
    edit.putBoolean(FIRST_RUN, false);
    edit.commit();
}

只需在第一个活动中设置一个shared preference ,比如with Boolean值为false的应用程序的启动,并在数据库设置值为true之后使用数据库执行任何操作,然后除非重新安装,否则不会调用该函数它或者只是不强行清除你的数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM