1

i have a public method in my MainActivity.java and want to call it from another Activity. Therefore i need the MainAcitivity Instance. How can i access it from another Acitivity.

Thanks

user1104836
  • 205
  • 1
  • 6
  • 16
  • 1
    This isn't something that should normally be required, but if it is: you just have to pass the activity to the other. If the second activity is created by the main activity, most likely pass it in the extras bundle. – HannahMitt Dec 01 '12 at 19:21
  • 3
    That's a sign of bad design. – Egor Dec 01 '12 at 19:24

2 Answers2

1

You can get help about message passing between activities by Broadcast Receivers

Ali Imran
  • 8,927
  • 3
  • 39
  • 50
0

As already mentioned in comments that "This isn't something that should normally be required", but still if you want this you can make that method static in MainActivity.java.

public static void someMethod()
{
}

and then in another activity, call this way:

MainActivity.someMethod();
Tahreem
  • 205
  • 5
  • 15