如何设置onBackButton监听到活动 [英] How to set onBackButton listener to an activity

查看:102
本文介绍了如何设置onBackButton监听到活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过 startActivityForResult 通过传递意图来运行活动的一类。在其他类中,可以说,BI得到这个意图和它重新创建活动。我怎么能听事件的活动,例如,这是开始为结果活动运行和用户pressed后退按钮,所以我想要做一些动作。 我怎样才能做到这一点? 感谢您在前进。

I have a Class A which runs activity via startActivityForResult by passing Intent to it. In other class, lets say B I get this Intent and recreate activity by it. How can I listen events for that activity, e.g. activity which was started for result is running and user pressed "back" button so I want to do some action. How can I do this? Thank you on advance.

活动中,我重新创建对象的实例,不是从活动类派生的。这只是活动。所以我只有对象。有没有办法做这样的东西与实例类,但不是一个班的?

Activity in which i recreate instance of object is not derived from Activity class. It is just ACTIVITY. So I have only object. is there any way to do such stuff with instance of class but not a class?

推荐答案

您应该覆盖的方法:<一href="http://developer.android.com/reference/android/app/Activity.html#onBack$p$pssed%28%29"><$c$c>onBack$p$pssed()活动的类。

You should override the method : onBackPressed() of the Activity class.

这篇关于如何设置onBackButton监听到活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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