Question

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!

Was it helpful?

Solution

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

enter image description here

OTHER TIPS

If you do not want to implement a submit button, you would be better off updating your database in onPause() instead of onDestroy().

@Override
    protected void onPause() {
        super.onPause();    
            if (isFinishing()) {
                //Database updates here
            }
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top