I'm having a hard time calling two methods created in my main activity by a handler. This handler is static, and when I throw its static attribute so that my non-static methods can be called, it returns an error saying that my handler can not be in a non static context. I am passing via handler a message that will be to trigger two methods that will record the voice and send by email respectively, everything working.
follow code
This is contained within my class for bluetooth connection
public class ConnectionThread extends Thread{
public void toMainActivity(byte[] data) {
Message message = new Message();
Bundle bundle = new Bundle();
bundle.putByteArray("data", data);
message.setData(bundle);
MainActivity.handler.sendMessage(message);(Erro Non static field "handler" cannot be refere
}
}
public Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
Bundle bundle = msg.getData();
byte[] data = bundle.getByteArray("data");
String dataString = new String(data);
//resultTEXT.setText(dataString);
if (dataString.equals("---N"))
resultTEXT.setText("Ocorreu um erro durante a conexão D:");
if (dataString.equals("---S"))
resultTEXT.setText("Conectado :D");
if (dataString.equals("---O")) {
resultTEXT.setText("Recebido!");
//se a mensagem recebida for a configurada no arduino é porque o botao foi clicado
localizacao = getlocation();
promptSpeechInput();
}
}
};
The problem is that promptSpeechInput and get location make use of methods and classes already ready that are in non static context. I can not find the problem. Does anyone have a light? this handler is inside my mainActivity receiving bluetooth information, that when the button is pressed the arduino will send the signal --- The