- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想在我的应用程序启动之前检查 SharedPreferences
。我想检查中的值是真还是假,并根据该值开始不同的 Activity (如果值为真,我想开始一项 Activity ;如果为假,我想开始第二项 Activity )。如何在显示我的应用程序首屏之前检查它?
最佳答案
i want to check shared preference before my app starts
根据定义,这是不可能的。如果您的应用尚未启动,则您的代码未运行,因此您的代码无法检查 SharedPreferences
。
If value is true i want to start one activity if it is false i want to start second activity.how to check it before showing my apps first screen?
让您的 Activity 自己处理一种情况(例如,true
)。在onCreate()
中,勾选SharedPreferences
,如果值为false
,则调用startActivity()
启动其他 Activity ,然后 finish()
摆脱当前 Activity (因为不再需要它)。
或者,只有一个 Activity ,但有两个不同的 fragment ,并根据 SharedPreferences
加载正确的 fragment 。
关于android - 在 App 启动前检查 sharedpreference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21076432/
我想知道以跨平台方式操作应用程序设置的最佳解决方案是什么。 在 iOS 中,我们可以在设置屏幕中更改应用程序外部的设置,但在 windows phone 和 android 中我们没有。 所以,我的想
我想清除除一个 SharedPreference 之外的所有内容。如果我已经保存了 10 个以上,有没有比单独删除每个更好的方法?这有点多余: preferences.edit().remove("1
我在名为 page1.dart 的页面中存储了一个值。我想从 page2.dart 或 page3.dart 访问存储的值。我怎样才能做到这一点? 最佳答案 Flutter 共享首选项实际上是作为内存
是否可以将 SharedPreferences 文件保存到自定义目录中?让我们说到 /data/data/package.name/my_prefs/。 或者是否可以检索默认保存 SharedPref
我很好奇存储库在 MVVM 架构中的作用。如果您决定将存储库添加到您的项目中,这个存储库是否只负责来自数据库或网络的数据?问题是关于 SharedPreferences 或 Files,我应该让存储库
尝试从服务创建共享首选项文件时出现以下错误: “无法为 SharedPreferences 文件/dbdata/databases/dimappers.android.pub/shared_prefs
所以我有这行代码 SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
This question already has answers here: What is a NullPointerException, and how do I fix it? (12个答案)
有谁知道 android 是否支持在一个项目中编译的多个 Android 模块之间共享相同的 sharedpreference? 我有两个共享首选项,目前当我尝试从当前模块外部的共享首选项访问一些数据
我正在搜索最大的 Android SharedPreferences 键值对,但找不到任何好的答案。其次,我想问一下,如果我有一个键,它的字符串值限制是多少。多少字符可以放入其中。如果我需要频繁更改值
我正在制作一个简单的预算跟踪应用程序。我有一个预算类,其中存储了一些变量:预算的金额、持续时间和初始值。我在 fragment 中只有一个全局预算对象,称为“预算”,我正在尝试保存它。它似乎保存得很好
我在 Flutter 应用程序中使用了 shared_preferences 插件,我想在用户选择城市时保存数据。 但是当我尝试打印它时,它只是说; Instance of 'SharedPrefer
我阅读了有关在 Flutter 应用程序中初始化 SharedPreferences 的其他答案(例如 this one ),但我想采取另一条路线:一开始就初始化 SharedPreferences
在我的 flutter 应用程序中,我实现了一个入职 View 。因为它应该只加载一次,所以我使用共享首选项来存储一个整数来表示已经显示了入职。当我在 Debug模式下运行应用程序时,一切正常。但是当
如果您使用 apply,在单独的线程中编辑共享首选项是否多余? 我的 MainActivity 的 onCreate 方法中有以下代码块: final MainActivity activit
我有 2 个 Activity ,身份验证和主页。 在身份验证中,它检查用户是否已登录,如果用户已登录,则将其重定向到Mainpage.class。这就是身份验证检查用户是否登录并重定向的方式。 Sh
为什么 toast 只显示空字符串或我在 getString 行上输入的“默认”值 @Override protected void onCreate(Bundle savedInstanceStat
我在我的项目中创建了一个模块。该模块的名称为“连接器”。现在我在 MainActivity 中创建 private SharedPreferences sPref; private S
刚接触 Java,很抱歉我的理解不够。我遇到了一个小障碍,我有一个用于连接到服务器的静态类。我正在为 SharedPreferences 使用另一个类,SharedPreferences 的一些详细信
这是一件好事。我将 int 值存储在我的共享首选项中,本质上是缓存它们,以便我可以在下次启动时将它们放入数据库中。我有一种方法可以在启动时将它们保存到数据库中。 接下来是从共享首选项中删除值以重置它们
我是一名优秀的程序员,十分优秀!