How Can I Call Main Activity Method in Another Class 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?

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest