杀死android中的一个activity
由于我的类无法继承 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您启动一个新活动来获得一些结果,那么您应该使用
startActivityForResult()
而不是startActivity()
。如果您想在执行一些必要的任务后停止活动,请在执行完所有必要的操作后在
onCreate()
末尾调用finish()
。如果您还有其他想法,请告诉我。我会尽我所能来帮助你。
If you started a new activity to get some result then you should use
startActivityForResult()
instead ofstartActivity()
.and if you want to stop an activity after performing some necessary tasks then call
finish()
at the end of theonCreate()
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.
你不知道。
你不知道。一般来说,一项活动不会完成另一项活动。
由于新活动在“下一个语句”时尚未显示,因此您一开始就不应该启动它。
You don't.
You don't. One activity does not finish another activity in general.
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.
您必须从 LAUNCHER 活动的 onCreate 方法传递上下文对象。
您可以使用下面的代码。
`public Class ABc{
}`
和
onCreate
方法创建此ABc
类的对象。You have to just pass contex object from LAUNCHER activity's onCreate method.
You may use below code.
`public Class ABc{
}`
And
onCreate
method create object of thisABc
class.