0

I have an activity which shows a List of items from the server. When the list Item is clicked I open up another detail activity. On the detail activity Iam doing some changes back to the server. So when I press back button i want to refresh the previous activity to make sure the changes I made reflect.

This is what I do currently :-

@Override
    protected void onRestart()
    {

        // TODO Auto-generated method stub
        super.onRestart();
        FetchItems fetchTask = new FetchItems();
        try {
            myFinalList = fetchTask.execute(registerContet).get();

            }
         catch (Exception e)
         {

            e.printStackTrace();
         }

    }

Everything works fine. But when I press the back button there is a UI freeze and it does not go back to the previous screen instantly. How can I solve this?

Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
hello world
  • 797
  • 1
  • 9
  • 31

3 Answers3

1

When you start your Detail Activity, use startActivityForResult. Then do whatever work you want in your Detail Activity and call setResult() and finish(). Finally, back in your first activity and override onActivityResult() grab whatever data you packed before the finish() and use it to refresh your list.

Further info and examples can be found here:

petey
  • 16,914
  • 6
  • 65
  • 97
  • The thing is I get a list in an activity and then pass the list to a fragment which displays it in a listview. I have the onclick event in the fragment. So OnActivityResult does not do a refresh – hello world Dec 04 '15 at 10:16
  • If you like this sort of approach but are using fragments, check out http://stackoverflow.com/q/6751583/794088 – petey Dec 04 '15 at 10:19
0

this sounds like a perfect use-case for an event bus like otta,greenDao, BUt if you dont want to use those you can put the refresh status flag in the intent and pass it to the activity.

Aniruddha K.M
  • 7,361
  • 3
  • 43
  • 52
0
public void onRestart()
{
super.onRestart();
    finish();
    startActivity(getIntent());
    overridePendingTransition(0, 0);
}