How Can Call One Activity Method from Another Activity in Android?

How Can Call One Activity Method from Another Activity in Android?
Contents

How can I call a function from another activity in Android?

public class MainActivity extends AppCompatActivity { // Instance of AnotherClass for future use private AnotherClass anotherClass; @Override protected void onCreate(Bundle savedInstanceState) { // Create new instance of AnotherClass and // pass instance of MainActivity by “this” anotherClass = new AnotherClass(this); …

How do you call a method in another activity from activity?

6 Answers. You can use startActivityForResult or you can pass the values from one activity to another using intents and do what is required. But it depends on what you intend to do in the method. If you need to call the same method from both Activities why not then use a third object?

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.