什么是建立在Android的登录屏幕/活动的正确方法是什么? [英] What is the correct way of creating a login screen/activity in Android?

查看:107
本文介绍了什么是建立在Android的登录屏幕/活动的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Android应用程序需要用户做任何事情之前登录。目前,我已经创建了一个名为LoginScreen主要活动,并成功登录后,本次活动启动另一个活动称为首页。但是,我看到一个问题,这种方法。如果什么用户presses回来在家活动的按钮?我不想让用户回到登录屏幕。什么是这样做停止用户的正确方法。我需要处理的关键preSS事件?

I am working on an Android application that requires a user to login before doing anything else. Currently I have created main Activity named LoginScreen and upon successful login this activity launches another Activity called Home. But I see a problem with this approach. What if user presses back button from Home activity? I dont want user going back to login screen. what is the correct way of stopping the user from doing that. Do I need to handle Key Press events?

推荐答案

我最后做的事是让我的家庭活动处理这个意图的 android.intent.action.MAIN 。家的活性,在启动时,检查用户是否在签名或不(使用共享preferences),如果它不是那么它开始LoginActivity并调用自身光洁度()。

What I ended up doing was to make my Home activity handle the intent android.intent.action.MAIN. Home activity, when launched, checks if the user is signed in or not (using shared preferences), if its not then it starts LoginActivity and calls finish() on its self.

LoginActivity成功登录开始的主要活动,这一次,因为用户登录时,主要业务将继续正常进程。 LoginActivity被声明为在清单文件如下:

LoginActivity on successful login starts the Main activity and this time because the user is logged on, the Main activity will continue its normal course. LoginActivity is declared as following in the manifest file:

<activity android:name="LoginScreen" android:label="@string/app_name"
    android:noHistory="true" android:excludeFromRecents="true">
</activity>

设置noHistory和excludeFromRecents为true LoginActivity意味着使用回退按钮,用户不能返回到这个活动。

Setting noHistory and excludeFromRecents to true for LoginActivity means that the user cant return to this activity using back button.

这篇关于什么是建立在Android的登录屏幕/活动的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆