how to call a method in another Activity from Activity

后端 未结 6 1841
广开言路
广开言路 2020-11-27 21:34

\'m developing an Android Application in which I have

I\'ve two classes class A and Class B .

In class A , I tried the code Snippets like below,

6条回答
  •  臣服心动
    2020-11-27 22:15

    Simple, use static.

    In activity you have the method you want to call:

    private static String name = "Robert";
    
    ...
    
    public static String getData() {
        return name;
    }
    

    And in your activity where you make the call:

    private static String name;
    
    ...
    
    name = SplashActivity.getData();
    

提交回复
热议问题