简体   繁体   English

如何捕获通过单击android活动右上角的X引起的事件

[英]How to catch the event caused by clicking on the top-right X of an android activity

I'd like to know what event Android issues when clicking on the top-right X of an Activity. 我想知道单击“活动”右上角的X时Android会发生什么事件。 I've tried onStop() and onDestroy() , but they don't get called at all. 我已经尝试过onStop()onDestroy() ,但是根本不会调用它们。

Please note that I'm using AppTheme.NoActionBar as app theme, and my Activity extends AppCompatActivity. 请注意,我使用AppTheme.NoActionBar作为应用程序主题,并且我的Activity扩展了AppCompatActivity。

Also, is it possible to remove the top-right X button (but keep drop-down menu)? 另外,是否可以删除右上角的X按钮(但保留下拉菜单)?

在此处输入图片说明

Looking at that image ,you are at "recently used" (or whatever it's called) section of your device. 查看该图像,您就可以看到设备的“最近使用过的”(或所谓的)部分。 If you are at that screen , onStop() is already called for your activity and when you click the X (close app) button , onDestroy() will be called. 如果您在该屏幕上,则已经为您的活动调用了onStop(),并且当您单击X(关闭应用程序)按钮时,将调用onDestroy()。

Override those lifecycle methods , onPause onStop etc and place Log statements inside them. 覆盖那些生命周期方法,onPause onStop等,并在其中放置Log语句。 Like this : Log.d("lifecycle","onStopCalled"); 像这样:Log.d(“ lifecycle”,“ onStopCalled”); and check your logcat whats happening 并检查您的logcat发生了什么

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

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