Hi all,

This is an intermittent bug in one of my apps. I don't expect anyone
to solve it immediately, but I'd appreciate any thoughts on how to
start debugging!

So, my app lets users edit an item (in the EditPage activity). When
they press the Back key, the desired behaviour is that it saves their
edits and returns them to the home page (the HomeList activity). The
code for this is below. It works fine. Except...

The bug is this. Some users report that sometimes when they reopen the
application after a pause, they are seeing *not* the home page, where
they left the application - but the previous edit activity. Crucially,
they are also seeing the edit activity without their saved edits -
effectively losing their most recent edits :(

I've been able to reproduce this myself. It only happens after the
application hasn't been opened for a while. If I save something,
minimize the application and reopen it straight away, it shows the
HomeList activity just fine, and the edits have all been saved. But if
I save something, leave it for a couple of hours and then reopen it,
it shows the previous EditPage activity, without the saved edits (i.e.
in the state that the EditPage activity was previously launched).

Any ideas, anyone? I had wondered whether it was due to the Back
button being used to return the user to the HomeList activity - maybe
Android thinks that the Back button means that the HomeList is not the
most "recent" activity, instead the EditPage is. I'd like to carry on
using the Back button if possible, though. And in particular, I'm
puzzled why it only happens after the app has been idle for an hour or
so, and not immediately? Is it something to do with Android's memory
management?

As I say, would appreciate any tips on how to debug - quite baffled at
the moment!

Thanks very much,

Anna

----------

Code used in the EditPage activity to save edits when the Back key
gets pressed. Works fine, apart from bug described above.

        // Save everything when the Back key gets pressed
        public boolean onKeyDown(int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                        if (saveEdits()) {
                                Context context = getApplicationContext();
                                CharSequence text = "'" + title + "' has been 
saved";
                                int duration = Toast.LENGTH_SHORT;
                                Toast toast = Toast.makeText(context, text, 
duration);
                                toast.show();
                                Intent i = new Intent(EditPage.this, 
HomeList.class);
                                startActivity(i);
                        } else {
                                // failed to save!
                                showDialog(SAVE_WARNING);
                        }
                }
                return false;
        }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to