哪个更适合在MainActivity或SubActivity上执行数据库查询

时间:2021-02-17 12:47:21

i currently following tutorial making notepad, this tutorial using 2 activity main activity and edit activity, edit activity is using to fill data for database , but the query is executed in main activity so the data must sent back OnActivityResult from edit activity to main activity .
the main question is i want to know why we must pass data to main activity instead of execute insert or update query on edit Activity, is this the best way?,

我目前正在制作记事本教程,本教程使用2活动主要活动和编辑活动,编辑活动用于填充数据库的数据,但查询在主活动中执行,因此数据必须将OnActivityResult从编辑活动发送回主活动。主要问题是我想知道为什么我们必须将数据传递给主要活动而不是在编辑Activity上执行插入或更新查询,这是最好的方法吗?

Can anyone explain why? Thanks

有人可以解释为什么吗谢谢

1 个解决方案

#1


0  

There you have the 2 activities, one (Main) is meant ust to display the notes, the other (Edit) will let the user to create the note. When the user confirms the creation of the new note in the EditActivity, it will finish and in the MainActivity's "onActivityResult" the notes will be loaded and displayed in the list. So if you want to separate the creation from the visualization of the (I highly suggest you to do this), you want this approach.

在那里你有2个活动,一个(主要)意味着要显示笔记,另一个(编辑)将让用户创建笔记。当用户确认在EditActivity中创建新笔记时,它将完成,并且在MainActivity的“onActivityResult”中,笔记将被加载并显示在列表中。因此,如果您想将创建与可视化(我强烈建议您这样做)分开,您需要这种方法。

#1


0  

There you have the 2 activities, one (Main) is meant ust to display the notes, the other (Edit) will let the user to create the note. When the user confirms the creation of the new note in the EditActivity, it will finish and in the MainActivity's "onActivityResult" the notes will be loaded and displayed in the list. So if you want to separate the creation from the visualization of the (I highly suggest you to do this), you want this approach.

在那里你有2个活动,一个(主要)意味着要显示笔记,另一个(编辑)将让用户创建笔记。当用户确认在EditActivity中创建新笔记时,它将完成,并且在MainActivity的“onActivityResult”中,笔记将被加载并显示在列表中。因此,如果您想将创建与可视化(我强烈建议您这样做)分开,您需要这种方法。