简体   繁体   English

小型建筑问题

[英]Small architecture question

I have a ListActivity which lists a bunch of "things." 我有一个ListActivity,其中列出了一堆“东西”。 If you click on one of these "things," you're taken to another ListActivity which lists a bunch of "stuff" for that "thing." 如果单击这些“事物”之一,您将被带到另一个ListActivity,其中列出了该“事物”的一堆“东西”。

Say I want to give the user the ability to edit the name of some of the "stuff"; 假设我想让用户能够编辑某些“内容”的名称; or even delete some of the "stuff." 甚至删除一些“东西”。 At what point should I actually perform that action on my database? 我实际上应该在什么时候对数据库执行该操作?

Ex: If a row of "stuff" gets deleted, should the database be updated before I return my user to the list of "things?" 例如:如果删除了一行“东西”,那么在我将用户返回“事物”列表之前,是否应该更新数据库? Or should the user return to the list of "things" and then the database is updated? 还是用户应该返回到“事物”列表,然后更新数据库? Or does it not matter? 或者没关系?

Mind you the database updating will likely happen in a service (I'll also be calling a web service to update the cloud). 请注意,数据库更新很可能会在服务中进行(我还将调用Web服务来更新云)。

I would do the database transaction after the user is finished messing with it, only because I would want to give them some way to undo an accidental deletion before committing it to the database. 我会在用户弄乱数据库事务之后再进行数据库事务,这仅仅是因为我想给他们一些方法,以在将其提交到数据库之前撤消意外删除。

Edit: See jball's answer. 编辑:请参阅jball的答案。 He understood you better than I did. 他比我更了解你。

It depends on what is important in your application. 这取决于您的应用程序中重要的内容。 If it's important that a user never thinks a child is deleted when it fails to delete, you should wait to get a response from the server before displaying the new list of children to the user. 如果重要的是用户在删除失败后再也不会认为该孩子被删除,则应在从服务器获得响应之前,向用户显示新的孩子列表。

However, if deletion confirmation is not so important and application responsiveness is critical, update the user's display and then do the deletion asynchronously behind the scenes. 但是,如果删除确认不是那么重要,并且应用程序的响应能力至关重要,请更新用户的显示,然后在后台异步进行删除。

You should definitly update the child activity as soon as the action is commited. 您应该在提交操作后立即更新子活动。 That way you will not have inconsistencies. 这样,您就不会出现不一致的情况。 Updating many changes to child activity when returning to parent, while exiting is risky, because if the network loses connection, you may not have all the changes fully committed. 返回父级时,退出时更新子级活动的许多更改是有风险的,因为如果网络失去连接,您可能无法完全提交所有更改。 This could lead to database inconsistencies. 这可能导致数据库不一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM