我可以创建一个处理整个应用的活动吗?

huangapple go评论60阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年5月4日 00:31:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/61577951.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定