注意:前提是界面二被打开过未关闭,则用此方法即可实现在界面一中调用界面二的方法!
界面一:
public class OneActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_one);
callTwoActivityMethod();
}
//调用另一个界面的方法
private void callTwoActivityMethod(){
if(TwoActivity.getObj()!=null){
TwoActivity.getObj().refresh();
}
}
}
界面二:
public class TwoActivity extends Activity {
private static TwoActivity mTwoActivity ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
mTwoActivity =this;
}
public static TwoActivity getObj(){
return mTwoActivity ;
}
//需要被调用的方法
public void refresh(){
//............
log.i("refresh","界面二的方法被调用");
}
}
本文出自 “龙源” 博客,请务必保留此出处http://zhangshenglong.blog.51cto.com/6624985/1434013
一个Activity调用另一个Activity的非静态方法,布布扣,bubuko.com
原文地址:http://zhangshenglong.blog.51cto.com/6624985/1434013