In android What is efficent way for use of Activity

元气小坏坏 提交于 2020-01-11 14:03:30

问题


I just want to ask what is efficient way of use activity. Mean use one activity for multiple functionality or use multiple activity for every functionality.

In my application working some thing like Category->subcategory->Product listing. In which orientation change design and also need to consume previous functionality state for Back.

Thanks


回答1:


Per the documentation for Activities, "An activity is a single, focused thing that the user can do". In other words, each different screen of your application should be an activity.

The only time you should have an Activity represent more than one screen is if it's a recursive action like a file browser; i.e. something that just changes the data that is displayed, but is displayed the same way.




回答2:


It's quite common to create one Activity for every logical "screen" of your application, but to share the same Activity for multiple "states" (eg. dialog boxes, different modes) of that screen.

The back button will automatically go backwards through Activities (by default) and you can override the back button within an activity to revert to a previous state within the same activity (ie. hiding a panel)




回答3:


Basically, Activity, in case of Android, is not a synonym for functionality. It is synonym for screen UI. Thus, how you implement your functionality is your choice. You just need to consider the following tips:

  1. If you use the same activity for categories and subcategories (using List elements), then you need time for deleting items for categories (plus, GC also takes time), populating the list with the values for subcategories. The weak points here that the user cannot return to the previous Activity using back button (this violates the default flow for user interactions), the screens are identical for categories and subcategories (this can mess the user), it will takes a long time for deleting unnecessary elements and populating with new elements. Strong point: you will reduce memory consumption for your application.
  2. The second option is to use different activities. Weak points: it also takes time to initialize new activity and to populate the list with the values of subcategories, it will take more memory to store two activities. Strong point: clear user understanding, more responsibility to user's actions (you do not need to run GC to delete unnecessary objects).

As for me the second approach is better unless you are not restricted with the memory.



来源:https://stackoverflow.com/questions/8709254/in-android-what-is-efficent-way-for-use-of-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!