关闭其他活动中的活动?
有谁知道如何从其他活动中关闭一个活动?例如:我有 3 个活动(活动 A、B 和 C),从活动 C 中,我可以关闭活动 A.. 我的活动结构是活动A ->活动B->活动C 如何从活动C中关闭活动A?
我尝试了这个代码:
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent goToLockScreen= new Intent(this,LockScreenForm.class);
startActivity(goToLockScreen);
finish();
但该代码只能从活动 B 中关闭活动 A,并且不能直接从活动 C 中关闭活动 A。
有谁知道如何直接从其他活动中关闭活动? 谢谢..
Does anyone know how to close an activity from other activity?? for example: i have 3 activity (activity A, B, and C) and from activity C, i can close an activity A..
my activity structure is activity A -> activity B -> activity C
how to close an activity A from activity C?
i was try this code :
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent goToLockScreen= new Intent(this,LockScreenForm.class);
startActivity(goToLockScreen);
finish();
but that code is only fot closing activity A from activity B, and can't close activity A from activity C direcly..
Does anyone know about closing an activity direcly from other activity??
thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试它对我来说完美地工作
现在你必须完成活动B中的活动A
活动B或第二个活动
try It work perfectly for me
Now You have to finish Activity-A from Activity-B
Activity-B or 2nd Activity
这是规定的方式,你应该遵循它..如果你想要一些其他行为,你可以实现它..关于这个主题有很多问题被问到..参考其他问题...
This is a prescribed way and you should follow it.. if you want some other behaviour yo can implement it.. there are lot many questions asked on this topic.. refer other questions...
启动 B 和 C
forResult
并将结果发送回之前的活动,让 A 最终调用finish()
怎么样?像这样:startActivityForResult()
->; BstartActivityForResult()
-> CC
setResult()
-> BonActivityResult(){setResult()}
-> ConActivityResult(){finish()}
听起来很复杂,但也许它可以用作解决方法?
What about starting both B and C
forResult
and send a result back to pervious activity to let A finally callfinish()
? Like this:A
startActivityForResult()
-> BstartActivityForResult()
-> CC
setResult()
-> BonActivityResult(){setResult()}
-> ConActivityResult(){finish()}
Sounds complicated, but maybe it can be used as a workaround?
尝试一下
如果更新活动正在启动另一个安装活动,那么您可能需要在更新活动中重写 void onActivityResult(int requestCode, int resultCode, Intent Intent) ,并提供以下实现。此外,当更新活动启动安装活动时,应该使用 startActivityForResult(Intent, int),而不是 startActivity(Intent)。
try this
If the update activity is launching another installation activity, then you may want to override void onActivityResult(int requestCode, int resultCode, Intent intent) in the update activity, providing the following implementation. Also, when the update activity launches the installation activity, it should do so with startActivityForResult(Intent, int), not with startActivity(Intent).