导航到上一个活动
我有两个屏幕,在第二个屏幕中我有一个显示第一个屏幕的后退按钮(使用意图)。如果我从第二个屏幕单击后退按钮,我会导航到第一个屏幕,没有问题..现在我想自动导航回第二个屏幕,而无需单击任何按钮。请帮助我我该怎么做。感谢您宝贵的时间。
I have two screens, in second screen i have one back button that shows the first screen(using intent). if i click that back button from second screen i navigated to first screen no probs in that.. now i want to navigate back to second screen automatically without clicking any button. Please help me how can i do this. Thanks for ur valuable time .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会尝试使用两个屏幕的
ViewFlipper
活动。当然,如果您可以将您的操作封装到一个活动中(我确信可以使用AsyncTasks
/Threads
、Services
和处理程序
)。这样您就可以使用手势、(软/硬)按钮、下拉菜单等在屏幕之间导航。
I would give a try to a
ViewFlipper
activity, with two screens. This, of course, if you can encapsulate your actions into one activity (which i'm sure is manageable withAsyncTasks
/Threads
,Services
andHandlers
).This way you can use gestures, (soft/hard)buttons, dropdowns, -whatever-, to navigate between your screens.
您可以通过调用
finish()
方法自动返回到 Activity 堆栈上的上一个 Activity。如果您想在没有任何用户交互的情况下执行此操作,请使用
Handler
,它会在预定义的超时后自动对您的 Activity 调用finish()
(请参阅 这篇文章了解有关处理程序的更多信息)。You can automatically go back to a previous activity on the Activity stack by calling the
finish()
method.If you want to do this without any user interaction, use a
Handler
that automatically callsfinish()
on your activity after a predefined timeout (see this article for more information on Handlers).尝试使用 Thread.sleep([ms]) 然后调用 finish 或调用第一个意图
try with Thread.sleep([ms]) and then call finish or call intent to the first
一种解决方案是,当您从第二个屏幕按“返回”按钮而不是调用 finish() 时;您应该再次启动第一个活动,因此活动堆栈将
在延迟两秒后您的活动将完成并最终返回到第二个屏幕,并且状态也将得到维护。
The one solution is, when you press BACK button from second screen instead of call finish(); you should start first activity again, so the activity stack will be
so after the delay of two second your activity will finish and eventually will come back to second screen, and state will be maintained also.