Answer the question
In order to leave comments, you need to log in
How to pass int to another class in this case?
There is a Response.java class that takes an array of bytes from the controller.
In it, I parse the answer I need, and transfer the data to Activiti for display.
public class Response {
private Response(byte[] data) {
// Работа со статусом
if (data.length==96){
// Определяем состояния двигателя
for (int i = 0; i < 8; i++) { //для первых 8-ми
if(data[i+8] != 0){
getEngineDanger(i);
continue;
}
if(isSet(data[3], i)){
getEngineStarted(i); //если стартовала (тру)
}else {
getEngineStopped(i);
}
}
}
}
// Передаем состояние по двигателям
public int getEngineDanger(int i){return i;} // Двигатель в аварии
public int getEngineStarted(int i){return i;} // Двигатель в работе
public int getEngineStopped(int i){return i;} //Двигатель выключен
// Побитовое смещение, определяем включен ли двигатель (Возращает boolean значение)
static boolean isSet(byte value, int bit){
return (value&(1<<bit))!=0;
}
@Override
public void onRead(Response response) {
setEngineButtonStarted(response.getEngineStarted());
}
Answer the question
In order to leave comments, you need to log in
If I understand the essence of the question, then you can do this:
interface OnResponseCallback {
void onResponse(int[] data);
}
class MainActivity implements OnResponseCallback {
public MainActivity() {
Response response = new Response(this);
}
@Override
public void onResponse(int[] data) {
//Обработка полученных данных
}
}
class Response {
OnResponseCallback mOnResponseComplete;
public Response(OnResponseCallback onResponseComplete) {
mOnResponseComplete = onResponseComplete;
returnDataToMainActivity();
}
void returnDataToMainActivity() {
mOnResponseComplete.onResponse(new int[] {1, 2, 3});
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question