简体   繁体   English

Android-如何检测用户何时单击最新应用?

[英]Android - How to detect when user click recent app?

I want to develop a custom launcher android for Samsung Tablet where user can only exit the launcher with a passcode input. 我想为三星平板电脑开发一个自定义启动器android,其中用户只能使用密码输入退出启动器。

Currently I face problem in recent app button. 目前,我在最近的应用程序按钮中遇到问题。 If user click recent app button, and then click the recent app, then click backpressed, device will go to TouchWiz launcher even I already set my launcher as a default launcher. 如果用户单击“最近使用的应用程序”按钮,然后单击“最近使用的应用程序”,然后单击“按下”,则即使我已经将启动器设置为默认启动器,设备也将转到TouchWiz启动器。 Also, I disable the notification bar so user can't access it. 另外,我禁用了通知栏,因此用户无法访问它。 However, when it go to TouchWiz via backpressed at recent app, the notification also disable, it should be able when in TouchWiz launcher. 但是,当通过最近使用的应用程序的backpressed进入TouchWiz时,该通知也将被禁用,在TouchWiz启动器中应该可以。

My proposed solution is to detect when user click recent app and forbid any action that can cause the changes of current view. 我建议的解决方案是检测用户何时单击最近的应用程序,并禁止任何可能导致当前视图更改的操作。

You can check onWindowFocusChanged method. 您可以检查onWindowFocusChanged方法。 You Activity will get a callback on this method when you click recent apps or press back button from it. 当您单击最近的应用程序或从中单击后退按钮时,您的活动将获得有关此方法的回调。 When you click on recent apps hasFocus will be false and when you press back it will be true. 当您单击最新的应用程序时,hasFocus将为false,而当您单击返回时它将为true。

documentation 文件

I can't detect the recent app clicked. 我无法检测到最近点击的应用程序。 So I use onPause() to detect if my app is on foreground or background. 因此,我使用onPause()来检测我的应用程序位于前台还是后台。 If is in onPause() then my app is on background, if so, I do startActivity(myLauncher) so other app won't launched. 如果在onPause()则我的应用程序处于后台运行;如果是,则执行startActivity(myLauncher)因此其他应用程序将不会启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM