英文:
Can I create only one activity that handles the whole app?
问题
我最近制作了一个包含大量执行不同功能的活动的应用,所以我想知道,我是否可以只创建一个活动。没有片段,什么都没有,只有一个活动,通过可能使视图可见或在需要时删除和添加按钮来随时更改它?或者那样会减慢我的应用程序的速度吗?
英文:
I recently made an app that contains tons of activities performing different functions so I was wondering, can I create only one activity. No fragments nothing, only one activity that changes every time I want it to by maybe making views visible or removing and adding buttons whenever I need them? Or will that slow my app down?
答案1
得分: 14
不,它不会减慢您的应用程序速度。事实上,从效率的角度来看,这比拥有多个活动更好,因为布局和创建新活动显然是耗费资源的。
但当然,当确实有意义拥有两个活动时,您应该创建两个活动,因为这将使代码更模块化,更易读,并且更容易编辑。
因此,您必须在效率和可读性之间取得平衡。
英文:
No it won't slow your app down. Infact, it is better than having multiple activities in terms of efficiency because laying out and creating a new activity is obviously expensive.
But of course, when it actually makes sense to have 2 activities, you should make two activities because that would make the code more modular, more readable and easily editable.
So you have to strike a balance between efficiency and readability.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论