I would say that multiple Activities almost always makes more sense. I just don't think Android is designed for constantly switching its own views - you miss out on so much. You have to implement Back yourself, you don't get any inter-Activity transitions, you have to implement a lot of internal logic to resume an application in the correct state. If you don't partition your app into Activities, it makes it a lot more difficult later on to change the flow of your application. It also results in one mega-Activity that can be a lot harder to handle than a lot of smaller pieces of code.
I have trouble imagining that speed is really an issue; if it is then there's something wrong with the way you're initializing each Activity. For example, I used try to pass Serializable objects between Activities, and that proved to be incredibly slow; when I switched to a faster method of passing objects, the speed of launching Activities increased immensely.
与其他的不同,我使用两者的混合,例如,
1. There is a main menu when the application starts
2. 点击搜索,进入搜索活动
3. 还有一个过滤器按钮,它可以切换视图并显示过滤选项
4.在过滤器视图的末尾有两个按钮,你点击“搜索”或“取消”,然后再次返回到搜索视图(没有切换活动)
5.现在,如果用户点击电话返回按钮,他将返回到主菜单,而不是搜索过滤选项。我想这是正确的行为。
I've experienced so many problems with multiple activity layout that I strongly discourage it, unless there's good reason to pick it.
多重活动的缺点
Using multiple activities it is much hard to refactor code to return data from activity.
如果你称一个子活动为“子活动”,那么主活动可能会被杀死。但是在一个像样的设备上进行调试时,您永远不会遇到这种情况,因此您需要处理始终保存状态和正确恢复状态。真是痛苦。想象一下在库上调用一个方法(即。另一个活动) ,并且您必须确保当该方法返回时,您的应用程序必须能够使用 VM 中所有对象上的所有字段完全重新创建其状态(即。Activity.restoreInstance).太疯狂了。
Fragments or just manage you activity views yourself. Managing views manually, requires coding some view-switching alternative to activities/fragments with transitions if desired.