Search code examples
androiddatabaseandroid-activityoncreateonresume

Android - child activity updates database on onDestroy and parent reads on onResume


I have 2 activities A->B. A is the parent activity and B is like "settings". In B the user makes some choices that update the app's database. A has to read the database to set some textviews in accordance to that.

What I thought would work is this: In B the user sets his choices (using some toggle buttons) and the on the onDestroy function the state of the buttons is read and the db is updated (I have no "submit changes button", so I use onDestroy). Then on the onResume function of A I call the routine that reads the db and updates the fields.

The problem is that the changes are not visible in A. But if I go again to B and back to A without any new changes then the changes are visible and correct.

So what is wrong and should be done? I can use a dummy activity between A and B and this may work, but I do not know if this is good implementation.. Thank you in advance!


Solution

  • Try instead of onDestroy() method for example onPause() or onStop() method. And look at this:

    enter image description here