0

In my android apps i have four activity A->B->C->D and in every activity i call web service then update the list-view and other element from the server so suppose i did delete some data from the database for Activity A and if user access the Activity B and he press the back button then Activity A should be refreshed. I did override onResume method and check the data is updated or not but didn't worked. I also tried another way but not achieve my goal.

my Activity structure is like a following

  • Class A Is Fragment which is having two tab and each tab contain listview
  • Class B Is Activity
  • Class C Is Activity
  • Class D Is Activity

I don't understand how to call web service again when press the back button and how to update fragment and activity when user press the back button. Please anybody suggest me some answer.

Thanks in advance

nilesh wani
  • 1,261
  • 5
  • 18
  • 30
  • Do all of these need to be activities? Or can they be represented as just Fragments? – BC2 Jul 12 '13 at 13:22
  • Have you tried overriding onRestart()? Anyway, I think you're best choice should be overriding onBackPressed() handling here what you want you're app to do. – Gian Segato Jul 12 '13 at 13:25

2 Answers2

0

you can override the OnBackPressed-method. check the top-answer on that link!!

Android: Proper Way to use onBackPressed() with Toast

Community
  • 1
  • 1
bofredo
  • 2,348
  • 6
  • 32
  • 51
  • 1
    The onBackPressed event will then be handled in the top must activity (in his case activity B) and not within the activity where the user returns to (here activity A). Therefore IMHO a better way would be to handle the refresh in the activity to which the user returns to by implementing the onActivityResult. – André Diermann Jul 12 '13 at 13:29
  • 1
    in this case trying to use onActivityResult will be the better attempt to get things running – bofredo Jul 12 '13 at 13:39
0

Start activity B from activity A with "startActivityForResult" instead of "startActivity".

In activity B you defaultly return RESULT_CANCELED -> so setResult(RESULT_CANCELED). Only when activity B is finished on purpose you return RESULT_OK.

In activity A you then just need to implement onActivityResult(). Depending on the result returned from activity B you can then do specific stuff in activity A, in your case refresh something.

Here is an example: http://www.vogella.com/articles/AndroidIntent/#usingintents_sub

André Diermann
  • 2,725
  • 23
  • 28