杀死android中的一个activity

发布于 2024-11-23 20:01:48 字数 111 浏览 2 评论 0原文

由于我的类无法继承 Activity 类,因此我使用 context.startActivity() 来启动一个新活动。在这种类型的启动中,如何杀死已启动的活动?在这种情况下我该如何使用 finish() ?

Since my class could not inherit Activity class, I used context.startActivity() to launch a new activity. In this type of launch, how can kill the launched activity.? How can i use finish() in this circumstance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柳絮泡泡 2024-11-30 20:01:48

如果您启动一个新活动来获得一些结果,那么您应该使用 startActivityForResult() 而不是 startActivity()

如果您想在执行一些必要的任务后停止活动,请在执行完所有必要的操作后在 onCreate() 末尾调用 finish()

如果您还有其他想法,请告诉我。我会尽我所能来帮助你。

If you started a new activity to get some result then you should use startActivityForResult() instead of startActivity().

and if you want to stop an activity after performing some necessary tasks then call finish() at the end of the onCreate() after performing everything necessary.

and if you have something else in your mind then let me know. I will try my level best to help you.

甜嗑 2024-11-30 20:01:48

在这种类型的启动中,如何杀死已启动的 Activity?

你不知道。

在这种情况下我该如何使用 finish() ?

你不知道。一般来说,一项活动不会完成另一项活动。

五月的下一句话就是杀死它。

由于新活动在“下一个语句”时尚未显示,因此您一开始就不应该启动它。

In this type of launch, how can kill the launched activity.?

You don't.

How can i use finish() in this circumstance?

You don't. One activity does not finish another activity in general.

May the very next statement is to kill it.

Since the new activity will not have been displayed by the time of "very next statement", then you should not have started it in the first place.

吹泡泡o 2024-11-30 20:01:48

您必须从 LAUNCHER 活动的 onCreate 方法传递上下文对象。

您可以使用下面的代码。

`public Class ABc{

         Contex co;
         ABc(Contex con){
               co=con;
          }
       con.startActivity(intent);

}`

onCreate 方法创建此 ABc 类的对象。

You have to just pass contex object from LAUNCHER activity's onCreate method.

You may use below code.

`public Class ABc{

         Contex co;
         ABc(Contex con){
               co=con;
          }
       con.startActivity(intent);

}`

And onCreate method create object of this ABc class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文