0

I am making an android application where i need to call a method in an activity from another activity. I have one main activity and several other ones. The other ones should execute a method in the main activity when the back button is pressed, how can i do so? I know how i can code the back button, but how do i call the activity from another activity? I am using no special or custom thread. Please help me and thanks so much in advance!

user1446632
  • 417
  • 2
  • 9
  • 24
  • possible Duplicate of http://stackoverflow.com/questions/6931168/android-access-method-in-an-activity-from-another-activity or http://stackoverflow.com/questions/2992656/android-activity-call-another-activity-method or http://stackoverflow.com/questions/5294473/calling-a-method-in-another-activity-from-an-activity – Rafael T Jun 12 '12 at 13:52

1 Answers1

0

There's an inherited method called onActivityResult(int requestCode, int resultCode, Intent data) Setting a result in the calling activity should let you execute code in the called activity.

Take a look here for an example and some tips: http://developer.android.com/reference/android/app/Activity.html

Jason L
  • 1,812
  • 2
  • 22
  • 43
  • I agree, onActivityResult is the best practice. if you don't want, you can also put your code in onResume of main activity and make a test on a static variable if the main activity is called from a specific activity, before executing. – Yvan RAJAONARIVONY Jun 12 '12 at 15:02