Home > Back-end >  Java callback problem
Java callback problem

Time:04-22

SDK code is as follows, a interface, there are multiple callback, the callback to intuitive, this definition, the outer APP I call, how to just call a function corresponding to the interface can be, don't also want to multiple callback. Like call restart, as long as there is @ Override
Public void onIpcReboot (int error_code) {

}
, others do not, is there a way to do this?


/* ** to restart the IPC 
*
* @ param ipc to restart the ipc
* @ param callBack returns true on success and "OK", or false on failure and the cause of the failure
*/
Public static void setReboot (IPC, IPC, final IPCCallBack callBack) {

Device findDevice=null;
For (Device Device: mDeviceList) {
If (device. GetIpAddress (.) the equals (ipc) getIp ())) {
FindDevice=device;
break;
}
}
SystemRebootThread SystemRebootThread=new SystemRebootThread (findDevice mContext, new SystemRebootThread. SystemRebootCallBack () {
@ Override
Public void onRebootResult (Boolean isSuccess, Device Device, String result) {

MyLog. E (TAG, result);
If (isSuccess) {
The callBack. OnIpcReboot (0);
}
The else {
The callBack. OnIpcReboot (1);
}
}
});
SystemRebootThread. Start ();
}

Public static String error_to_string (int error_code) {
return null;
}

Public interface IPCCallBack {

/* *
* search IPC CallBack
*
* @ param error_code successfully returns 0, failure to return error_code
* @ param ipc_list returned to detect the IPC
*/
Void onIpcSearchResult (int error_code List Ipc_list);

/* *
* the pictures of the IPC CallBack
*
* @ param error_code successfully returns 0, failure to return error_code
* @ param abs_path pictures returns the absolute path
*/
Void onIpcSnapshot (int error_code, String abs_path);

/* *
* set the IPC time
*
* @ param error_code successfully returns 0, failure to return error_code
*/
Void onIpcSetTime (int error_code);

/* *
* set the IP address of the IPC
*
* @ param error_code successfully returns 0, failure to return error_code
*/
Void onIpcSetIP (int error_code);

/* *
* to restart the IPC
*
* @ param error_code successfully returns 0, failure to return error_code
*/
Void onIpcReboot (int error_code);

/* *
*
* @ param error_code successfully returns 0, failure to return error_code
*/
Void onIpcSetImage (int error_code);

/* *
* set the IPC video coding
*
* @ param error_code successfully returns 0, failure to return error_code
*/
Void onIpcSetVideoEncoder (int error_code);

/* *
* set the IPC OSD
*
* @ param error_code successfully returns 0, failure to return error_code
*/
Void onIpcSetOsd (int error_code);
}


 IpcSDK. SetReboot (m_IPC, new IpcSDK IPCCallBack () {
@ Override
Public void onIpcSearchResult (int error_code List Ipc_list) {

}

@ Override
Public void onIpcSnapshot (int error_code, String abs_path) {

}

@ Override
Public void onIpcSetTime (int error_code) {

}

@ Override
Public void onIpcSetIP (int error_code) {

}

@ Override
Public void onIpcReboot (int error_code) {

}

@ Override
Public void onIpcSetImage (int error_code) {

}

@ Override
Public void onIpcSetVideoEncoder (int error_code) {

}

@ Override
Public void onIpcSetOsd (int error_code) {

}
});

CodePudding user response:

Write an abstract class such as AbstractIpcRebootCallback, realize onlpcReboot outside interface method (method doesn't do anything), only keep onlpcReboot interface realization method (abstract), outer app called, the parameter to this abstract class instance
  • Related