Android应用程序与多个视图 - 最佳实践?多个、视图、应用程序、Android

2023-09-05 11:28:38 作者:扶苏

我是新开发的机器人。我有一些最佳实践的问题。我的应用程序就像是一个仪表板从多个不同的子活动就可以启动并完成。

I am new to developing for android. I have a question regarding some best practices. My app is like a dashboard from which multiple different "sub-activities" can be started and done.

我想知道什么是构建应用程序的最佳途径。一种方法是将有不同的布局和负载,并适当卸载它们。另一种是开始使用意图的新活动。至少,这是我从我已阅读聚集。

I am wondering what is the best way to structure the app. One way is to have different layouts and load and unload them appropriately. The other is to start new activities using intents. At least this is what i have gathered from what i have read.

什么你认为是最好的一段路要走。

What in your opinion is the best way to go.

感谢

推荐答案

我在我的应用程序已经发现,每个活动一般负责一个UI视图。

I've found in my applications that each Activity is generally responsible for a single UI view.

所以,与其装卸不同的布局,这可能得到相当凌乱,最好是每个子活动分成了自己的活动类,并使用明确的意图(意图依靠的是命名目标活动明确,而不是意图过滤器),在它们之间移动。

So rather than loading and unloading different layouts, which can potentially get quite messy, it is better to separate each sub-activity into its own Activity class and use explicit intents (intents that name the target activity explicitly rather than relying on an intent filter) to move between them.