简体   繁体   中英

App home button not preserving data

On my apps home page I have an option to add items to a ListView using adapter.add(string) . I also have another Activity that my app goes to using startActivity(intent) . When I am in that second Activity and I press the back button all of the data that was added to the list is still there, however when I press the icon at the top left all the data is gone. Is there a way to make it so that the button for the icon preserves the data in my list. I think I should note that I don't want the data to be preserved when the app is closed, only when navigating through the open app.

This is my current method that handles the home button action:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            NavUtils.navigateUpFromSameTask(this);
            return true;
    }
    return super.onOptionsItemSelected(item);
}

A quick solution would be to call onBackPressed() instead of NavUtils.navigateUpFromSameTask(this) . This, however, isn't recommended and you should try to implement proper navigation logic. Take a look at the answers to this question as well as these tips.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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