简体   繁体   English

在活动之间切换

[英]Switching between activities

I have a dashboard Activity and a user Activity . 我有一个仪表板Activity和一个用户Activity On every operation in dashboard I will start user Activity using startActivity( ). 在仪表板上的每个操作上,我将使用startActivity( )启动用户Activity If the user pressed back button in user Activity I want to show dashboard Activity again. 如果用户在用户“ Activity按下了“后退”按钮,我想再次显示仪表板“ Activity Please give guidelines to implement this which should also handle when the dashboard Activity is killed due to low memory. 请提供实施此准则的准则,该准则也应在由于内存不足而导致仪表板“ Activity被终止时处理。

The Android framework will take care of that for you. Android框架将为您解决这一问题。 When you call startActivity() it pushes the new activity on top of the current task's stack (unless you tweak the launch mode or set intent flags) 当您调用startActivity()它将新活动推入当前任务的堆栈顶部(除非您调整启动模式或设置意图标志)

When the user presses back, it pops the current activity off the stack and returns to the previous activity. 当用户按下时,它将当前活动从堆栈中弹出并返回到上一个活动。

If the framework killed any of the previous activities, they are recreated. 如果框架杀死了之前的任何活动,则将重新创建它们。 If you had any instance data in those activities that you still need, you should override onSaveInstanceState() to store it and onRestoreInstanceState() to recover it (data in system Views that have ids assigned are automatically saved/restored). 如果在那些活动中仍需要任何实例数据,则应重写onSaveInstanceState()进行存储,并onRestoreInstanceState()进行恢复(系统视图中已分配ID的数据将自动保存/恢复)。

Please see Tasks and the Back Stack for details. 有关详细信息,请参见任务和Back Stack

The only potentially tricky part is if you jump into the application on the user page via intent, but still want back to go to the dashboard, you will need to be sure to prepare the back stack via a TaskStackBuilder . 唯一可能棘手的部分是,如果您通过意图跳入用户页面上的应用程序,但仍想返回到仪表板,则需要确保通过TaskStackBuilder准备后向堆栈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM