是什么改变活动时,最好的做法是什么? [英] What are the best practices when changing activities?

查看:126
本文介绍了是什么改变活动时,最好的做法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何的最佳做法,改变Android的活动时,?

这似乎很奇怪我,只是让一个Intent又一遍地再掀活动。

如果我刚开始另一个活动,并完成最后一个,当我有回迁的,我需要加载所有的东西回来。但是,当我不这样做,似乎并不在内存处理方面做正确的事。

是不是正确的所有活动保存在一种ActivitiesPool还是这样呢?或者我会永远保持他们打开或重新加载它们之间做出选择?

任何方向?

感谢


解决方案

  

这似乎很奇怪我,只是让一个Intent并在启动另一个活动和奥雅纳


这就是它是如何工作在Android上。为了更precise我们(作为开发人员),甚至没有系统允许调用新活动()您只需 startActivity(意向) ;


  

我需要加载所有的东西回来


再次,根据需要的框架正在装货的护理/卸载资源


  

是不是正确的所有活动保存在一种ActivitiesPool的


没有,这不是正确的,不要碰他们。

如果您希望用户能够点击按钮,然后转到previous活动,不叫完成( ); 就可以了。您可以使用的onPause() / onResume()回调处理后台操作和UI状态应该被保存在 @覆盖保护无效的onSaveInstanceState(捆绑outState)回调。你把你在那里需要的所有UI状态。如果系统需要的内存会破坏活动,只要用户将来,它会重新创建的onCreate(捆绑savedInstances)键,那么你就必须所有的UI状态保存在这里为你适当的重新创建,用户是之前的状态。

这是如何工作的。

Is there any best practices when changing activities in Android?

It seems very odd to me, just make an Intent and start another activity over and over.

If I just start another activity and finish the last one, when I have to move back, I need to load all the stuff back. But when I don't do it, does not seem to be the right thing to do in terms of memory handling.

Is it correct to save all the activities in a kind of ActivitiesPool or something like this? Or I will always have to choose between keeping them opened or reload them?

Any directions?

Thanks

解决方案

It seems very odd to me, just make an Intent and start another activity over and ove

that's how it works on Android. To be more precise we (as developers) are not even allowed by the System to call new Activity() you just startActivity(intent);

I need to load all the stuff back

again, the framework is taking care of loading/unloading resources as needed

Is it correct to save all the activities in a kind of ActivitiesPool

no, it's not correct, don't touch them.

If you want the user to be able to click the back button and go to the previous activity, DO NOT call finish(); on it. You can use onPause()/onResume() callbacks to handle background operations and UI status should be saved on @Override protected void onSaveInstanceState(Bundle outState) callback. You put all the UI state that you need in there. If the system needs memory it will destroy the activity and whenever the user is going back to it, it will create it again onCreate(Bundle savedInstances) and then you'll have all the UI state saved there for you to proper re-create the state where the user was before.

That's how it works.

这篇关于是什么改变活动时,最好的做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆