-2

我们如何在不使用android意图的情况下从另一个活动中调用一个活动的功能?

4

1 回答 1

0

使函数/方法公开和静态,然后您可以通过 classname.method() 引用它

public class ActivityA extends Activity{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ActivityA_layout);
        ActivityB.functionInActivityB(); // Calling function defined in ActivityB
    }
}

public class ActivityB extends Activity{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ActivityB_layout);
    }

    public static void functionInActivityB(){
        // Things To Be Done In ActivityB
    }
}
于 2013-09-26T09:25:53.713 回答