如何跳过不需要的活动?安卓
我正在为我的应用程序进行启动设置设置,我想知道如何让它在他们已经输入一次后跳过注册页面?我想的是一个 if 语句,但我不太擅长 android 中的 if 语句,所以有人能给我指出解决方案的方向吗?
im doing a starting setup settings thing for my app and i was wondering how i can get it to skip the sign up page once they have already entered once? an if statement would be the thing I thought but im not so good with if statements in android so could anyone point me in the direction for a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
输入并保存登录数据后,在
SharedPreferences
中存储一个值(例如booleanloggingIn=true
)。然后,每次启动应用程序时,都会从SharedPreferences
获取值,并决定是否显示登录窗口 (loggedIn==false
) 或不显示 (loggedIn==真
)。Store a value in
SharedPreferences
(e.g.boolean loggedIn=true
) once the login data has been entered and saved. Then every time you start your app get the value fromSharedPreferences
and decide whether to show the login-window (loggedIn==false
) or not (loggedIn==true
).我通过将没有 UI 的 Activity 作为启动活动来完成此操作,该活动检查首选项设置是否存在,然后根据首选项设置是否存在启动注册活动或主活动。
在 androidmanifest 中,您可以使用类似以下内容注册没有 UI 的活动(如果我没记错的话):
启动您选择的活动后,您需要在无 UI 活动中调用 finish()
I've done this by having an Activity with no UI as my startup activity which checks for the existence of a prefernce setting and then launches either the sign up activity or the main activity depending on whether or not the preference setting exists.
In the androidmanifest you can register your activity with no UI using something like this (if I remember correctly):
After launching your chosen activity you need to call finish() in the UI-less activity
您应该维护一个布尔值并将其保存在 SharedPreference 中并在那里检查它并相应地执行您的任务......
you should maintain a boolean and save it in SharedPreference and check it there and perform your task accordingly.......