安卓:如何调用方法只对安装的App [英] Android: how to call method only on installation of App
本文介绍了安卓:如何调用方法只对安装的App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要调用一个方法(或启动一项活动,还是其他什么东西),将更新包含的数据应用需求的文件。
I need to call a method (or start an activity, or something else) that will update a file containing data the app needs.
但我希望它是只进行一次,在首次安装应用程序;因为后,我会处理文件的更新自己。
But I want it to be done only once, when the app is first installed; because after I will handle the update of the file myself.
请怎样才能做到呢?
感谢您的任何建议。
推荐答案
做一些事情只有一次在应用程序,你需要的是这样的:
to do something only once in app you need something like this :
boolean mboolean = false;
SharedPreferences settings = getSharedPreferences("PREFS_NAME", 0);
mboolean = settings.getBoolean("FIRST_RUN", false);
if (!mboolean) {
// do the thing for the first time
settings = getSharedPreferences("PREFS_NAME", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("FIRST_RUN", true);
editor.commit();
} else {
// other time your app loads
}
这篇关于安卓:如何调用方法只对安装的App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文