如何设置onBackButton监听到活动如何设置、onBackButton

2023-09-12 04:39:22 作者:手放开.

我有一个通过 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?

推荐答案

您应该覆盖的方法:onBack$p$pssed()在活动的类。

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