我可以在Android Studio中使用单个输入表单从多个Activity收集数据吗?

vktxenjb  于 2022-11-16  发布在  Android
关注(0)|答案(1)|浏览(266)

大家好!今天大家好!
在Android Studio中有几个活动我必须获得数据。总共6个数据输入。但是一个用户只为其中一个输入数据。
这是设计草图。
那么,我是否必须使用这样的输入表单来设计6个活动,或者是否有任何方法可以使用一个输入表单来用于6个活动,并将具有唯一表单值的数据导入数据库?
如BanquetStarter(名称、地址..)、BanquetBronze(名称、地址..)等。
感谢您的帮助。感谢您宝贵的时间。谢谢。

gpnt7bae

gpnt7bae1#

These are separate screens, but do not necessarily have to be separate activities. Consider architecting this with Fragment s. This would allow you to utilize a single ViewModel bound to the lifecycle of the Activity . Each fragment would be responsible for collecting its own information and handing that into the ViewModel , and then once all the information is submitted, you have it all in one place and ready to go.
Activities are heavy weight components, whereas Fragments are lighter weight. Unless you have a very good, explicit reason to do so, prefer a single activity approach with multiple fragments (or multiple composable screens, if this app is being written from scratch utilizing Jetpack Compose).

相关问题