最佳做法在Android的活动调用完成()?做法、Android

2023-09-12 05:13:57 作者:╄→寒冷的冰 ;

我的大部分活动,从服务器加载动态数据,并在页面回来成为关注的焦点,我重装也无妨。这似乎浪费,让他们身边,如果我只是要重新加载它们,所以我想调用完成()在他们身上,如果用户离开页面。它如果有些活动,你可以preSS后退按钮去和其他人没有任何混乱,因为我要求他们完成(),所以我在想,如果不好的做法只是为了呼吁所有活动用户完成()从导航离开? (我在每一次活动的底部,所以必要的后退按钮心不是一个导航栏)。或者,是更好的做法不叫任何活动的结束(),只是希望他们不要减慢手机和操作系统会照顾垃圾收集呢?我是新来的Andr​​oid编程,并且没有一款Android手机,所以我不知道什么是在这种情况下,普通/最佳实践,或者如果个人口味的问题而已。

Most of my activities load dynamic data from a server, and when the page comes back into focus, i reload it anyway. It seems wasteful to keep them around if i'm just going to reload them, so I thought of calling finish() on them if the user navigates away from the page. Its confusing if some activities you can press the back button to go to and others no because I've called finish() on them, so I was wondering if its bad practice just to call finish() on all activities the user navigates away from? (I have a navigation bar at the bottom of every activity so the back button isnt necessary). Or, is it better practice not to call finish() on any of the activities and just hope they dont slow down the phone and that the OS will take care of garbage collecting them? I'm new to Android programming and and don't have an Android phone so i'm not sure what is the common/best practice in this situation, or if its just a matter of personal taste.

此外,是否有可能指示机器人以保持活动的历史记录,这样后退按钮仍然有效,但完成()他们,当他们浏览到别处,使他们没有不必要的占用资源?

Also, is it possible to instruct Android to keep a history of activities so that the back button still works, but finish() them when they navigate away so that they're not needlessly taking up resources?

推荐答案

虽然你可能重新加载在返回活动中的所有数据,还有关于调用完成()。

While you may reload all your data on returning to the activity, there is still no point on calling finish().

当活动是隐藏的,它们不使用的资源,并且是没有真正的问题。只要保持这些设置,然后当用户返回时,将重新加载它需要的。

When activities are hidden, they do not use resources, and are of no real problem. Just leave them as is, and then when the user navigates back, it will reload it as required.

在这种状态下,它们也可以被垃圾回收如果需要的话 - 这是Android的所有照顾

In this state, they can also be garbage collected if required - which is all taken care of by android.