我有一个界面MyListner
public interface MyListner{
public void onOperationComplete();
}
我有两个实现MyListner的Activity SignIn和SignUp
public class SignIn extends Activity implements MyListner{
@Override
public void onOperationComplete(){
Log.e("SignIn","Operation Complete");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Operation.doOperation();
}
}
public class SignUp extends Activity implements MyListner{
@Override
public void onOperationComplete(){
Log.e("SignUp","Operation Complete");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Operation.doOperation();
}
}
在两个Activity的onCreate()内,我正在类Operation内调用静态函数doOperation(),以通过Operation.doOperation()进行某些操作。
public class Operation{
publis static void doOperation(){
...........
...........
...........
//here i want a callback to interface funtion onOperationComplete()
}
}
我的要求是我想在实现MyListner的所有类中获取对函数onOperationComplete()的回调
最佳答案
使您的doOperation像这样:
public class Operation{
publis static void doOperation(MyListener callBack){
...........
...........
...........
//here i want a callback to interface funtion onOperationComplete()
callBack.onOperationComplete();
}
}
在您的活动中:
public class SignIn extends Activity implements MyListner{
@Override
public void onOperationComplete(){
Log.e("SignIn","Operation Complete");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Operation.doOperation(this);
}
}