区分Home键Android中activitys功能和后退按钮? [英] Differentiate the functionality of home button and back button in android activitys?

查看:134
本文介绍了区分Home键Android中activitys功能和后退按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有6 activitys A,B,C,D,E,F.In这个A是一个活动,我去到活动中B链登录后登录活动,C,D,E,F..In这B,C,D,E,F activitys每当用户preSS后退按钮它会回到以previous活动,如果用户preSS home键打开应用程序后,它会再次询问密码如何可能??请帮助我

I have 6 activitys A,B,C,D,E,F.In this A is a login activity after login in A activity i go to the activity chain B,C,D,E,F..In this B,C,D,E,F activitys whenever the user press back button it will go back to to previous activity if user press home button after opening the application it will again ask the password how it is possible..?? help me please

推荐答案

您可能在某处保持布尔条件共享preference 。在用户登录,其设置为true。一看便知这里的<一个href=\"http://stackoverflow.com/questions/2208912/how-can-i-detect-user-$p$pssing-home-key-in-my-activity/\">How我可以检测用户pressing HOME键在我的活动?问题,以检测是否首页是pressed。如果检测到首页键,共享preference 布尔 $ C>到。在 onResume 当检测首页按钮的活动,检查共享preferences变量值。如果是假,那么你就可以打开所有其他顶部的登录活动,并删除所有其他在堆栈中。

You might keep a boolean condition somewhere in SharedPreference. On user login, set it to true. See the answer here on How can I detect user pressing HOME key in my activity? question to detect if HOME was pressed. If HOME key is detected, set boolean in Sharedpreference to false. Inside onResume of the activity where HOME button is detected, check the variable value from SharedPreferences. If false, then you can open the login activity on top of all others and remove all others in the stack.

您不需要做具体的后退按钮pressing什么。但如果你要检测它,你可以重写 onBackButton pressed

You don't need to do anything specific on Back button pressing. Although if you want to detect it, you may override onBackButtonPressed.

这篇关于区分Home键Android中activitys功能和后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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