1

I have scenario with two screens.

  1. Screen 1 shows data from from API in list format
  2. There is a "+" button in menu bar
  3. Clicking this button takes user to screen 2
  4. User can enter some info on screen 2 and press the "save" button on top of this screen. This does a POST to my API and saves the data.

After saving, I would like to put the user back to screen 1. I've done that with this:

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
    if (menuItem.getTitle().toString().equalsIgnoreCase("save")) {
        new CreateSomethingTask(this,enteredName.getText().toString(), id).execute();
        Intent listscreen = new Intent(getApplicationContext(), ShowListActivity.class);
        startActivity(listscreen);
        return true;
    }
    return true;
}

However, the added item is not shown. If I close my app and open it again then the item shows up.

Is there a good way to handle this? I like how the Github Android app handles this when creating a new Gist. But I'm not sure how to implement that.

birdy
  • 9,286
  • 24
  • 107
  • 171

2 Answers2

0

You should start your screen2 with startActivityForResult(). That way you could send a result back and a code and proceed to refresh your screen1. See example : How to manage `startActivityForResult` on Android?

Community
  • 1
  • 1
Quanturium
  • 5,698
  • 2
  • 30
  • 36
-1

Below function maybe help you, didn't tried.

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();

    callFunctionToRefreshList();
    //or redraw data from api
    //setContentView(R.layout.activity_book);
}
Merter
  • 156
  • 2
  • 3