gpt4 book ai didi

android - 在 App 启动前检查 sharedpreference

转载 作者:太空宇宙 更新时间:2023-11-03 12:08:17 25 4
gpt4 key购买 nike

我想在我的应用程序启动之前检查 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com