0

I have two activities A and B. in A I start B activity. In B acitivity when user press back button I need to update A's layout values. So I need to know

In acitivity A which function will be called when return back to activity A.

Ismail Sahin
  • 2,640
  • 5
  • 31
  • 58
  • possible duplicate of [How to run code when coming back to activity](http://stackoverflow.com/questions/13220091/how-to-run-code-when-coming-back-to-activity) – Ultimo_m Jun 23 '14 at 19:26
  • How will you get the values to update? From where? – codeMagic Jun 23 '14 at 19:28
  • http://stackoverflow.com/questions/18243515/android-going-back-to-previous-activity-with-different-intent-value/18243541#18243541 – codeMagic Jun 23 '14 at 19:30
  • 1
    @ismail: I don't understand your edit. onResume is the right choice because it's exactly what you're asking, and no extra. You want to update the layout every time the activity is resumed, onResume will only update whenever the activity is resumed. – RogueBaneling Jun 23 '14 at 19:36
  • @RogueBaneling you are right I thouth that onResume called in every time that acitivity view is visible e.g every milisecond. – Ismail Sahin Jun 23 '14 at 19:42

3 Answers3

2

try and override onResume() function in A. works for me.

Ronn Wilder
  • 1,228
  • 9
  • 13
  • Is this proper function to do layout update? I think this will couse owerhead for memory – Ismail Sahin Jun 23 '14 at 19:27
  • This will also be called when the Activity first launches which I don't think is what the OP wants – codeMagic Jun 23 '14 at 19:27
  • It is run whenever the activity first launches, and whenever the back button is pressed and the activity is resumed to. Therefore you can try and use a try/catch to catch a RuntimeException so that there's no crash when it is loaded the first time the application starts. – RogueBaneling Jun 23 '14 at 19:29
1

Take a look at the Android life cycle: http://developer.android.com/reference/android/app/Activity.html

You will see that when you return to Activity A, function onResume() will be called.

Prince John
  • 642
  • 1
  • 4
  • 17
1

A key point when learning Android API is the Activity Lifecycle.

When an activity is displayed : it's onResume() method is called. So it will be called:

  • when the Activity is displayed for the first time (after onCreate(...))
  • every time the activity came to front
  • after activity re-created (for instance, after screen rotation)

For more details read this : activity pausing-resuming and more global overview of the lifecycle.

The Activity javadoc is also very good resource

ben75
  • 29,217
  • 10
  • 88
  • 134