活动与应用程序的片段
我一直在试图解决这个问题。我看到很多开发人员和YouTuber(教程)说,我们应该使用尽可能少的活动,以便进行更快,更高效,更少的资源重型代码/应用程序。我想知道是否有一种方法可以仅使用MainAttivity登录和注册来登录和注册,并结合片段进行导航。
或
我们是否需要至少2个或更多的活动来处理该过程(登录注册)?
示例:1个登录活动和1个活动的活动。
感谢并欢迎有关此主题的任何答案!
I have been trying to figure this out for a bit now. I see a lot of developers and youtubers (tutorials) saying that we should use as little activities as possible in order for a faster, more efficient and less resource heavy code/app. I was wondering if there is a way to create a Log-in and Sign-up using only the MainActivity for both Log-in and Sign-Up in combination with fragments for navigation between them.
Or
Do we need atleast 2 or more activities to handle that process ( Log-in & Sign-Up )?
Example: 1 activity for log-in and 1 activity for sign-up.
Appreciate and welcome any answers regarding this topic!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从理论上讲,您可以将整个应用程序运行在一个活动上,并在所有页面上使用片段。
每个片段在活动中都有自己的生命周期。
MainAttivity看起来像是这种
登录范围看起来像是这种
登记板看起来像是这样
基本上,我们通过调用loadFragment替换了活动中显示的片段。
该逻辑可以应用于必要的尽可能多的片段。
Theoretically, you could have your entire application run on a single Activity and use Fragments for all of the pages.
Each fragment has its own lifecycle within the activity.
MainActivity can look like this
LoginFragment can look like this
RegisterFragment can look like this
Basically, we replace the fragment displayed in the activity by calling loadfragment.
This logic can be applied to as many fragments as is necessary.