Android - Calling a method in one activity from another, without starting new activity

后端 未结 4 1930
北荒
北荒 2020-12-19 20:47

I\'m developing an Android app using GreenDroid. The application is just for testing atm, so it all it contains is an ActionBar with a refresh button, three tabs, and an act

4条回答
  •  长情又很酷
    2020-12-19 21:41

    If you don't want the other Activity instantiated, then that's not the place for this method. If it's shared functionality between more than one Activity, why not create a base class for your activities that derives from Activity.

    public class ActivityBase extends Activity
    {
    public void showToast()
    {
    ...
    

    Then your activities derive from this

    public class MyActivity extends ActivityBase
    {
    public void someMethod()
    {
    showToast();
    

提交回复
热议问题