OnClick重启Activity?
如何在单击时重新启动活动?
例如:我在我的 AndroidManifest.xml
2 个活动中获得了活动 A 和 B,它们在应用程序启动时启动...
但我想要的是当我单击活动 A 上的按钮时它必须重新启动 Activity B。
How can I restart An Activity on click?
For exemple: I have got in my AndroidManifest.xml
2 activities the activity A and B and they start when application starts...
But what I want is when I click in a button that is on Activity A it must restart activity B.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么需要在启动应用程序时启动这两个 Activity?当您说“重新启动”时,您实际上需要停止 Activity B 并再次启动 Activity B 吗?或者你只是想展示它?要从另一个 Activity 启动一个 Activity,您可以这样调用:
Android 文档提供了大量详细信息。但是,我认为您应该考虑为什么要同时启动两个活动,以及您是否可能想使用
Service
来代替(我不能说不知道您的应用程序的任何详细信息)。Why do you need to start both Activities on starting your app? When you say "restart", do you actually need to stop Activity B and start Activity B again? Or do you just want to show it? To start an Activity from another Activity, you could call something like this:
The Android documentation gives plenty of detail. However, I think you should consider why you are starting two activities at once, and whether you might want to use a
Service
instead (not knowing any details of your app, I can't say).在视图方法的
onClick
上调用上面的代码。call above piece of code on
onClick
of view method.当您处于活动 A 并继续进行活动 B 时,您的活动 B 会自动启动/重新启动
when you are in activity A, and proceeding to activity B, then your activity B automatically starts/re-starts