问题描述
是否有任何的最佳做法,改变Android的活动时,?
这似乎很奇怪我,只是让一个Intent又一遍地再掀活动。
如果我刚开始另一个活动,并完成最后一个,当我有回迁的,我需要加载所有的东西回来。但是,当我不这样做,似乎并不在内存处理方面做正确的事。
是不是正确的所有活动保存在一种ActivitiesPool还是这样呢?或者我会永远保持他们打开或重新加载它们之间做出选择?
任何方向?
感谢
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);
again, the framework is taking care of loading/unloading resources as needed
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.
这篇关于是什么改变活动时,最好的做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!