i am really new to Android and i was trying to use the Thread class with a message handler, in there i need to use the ApplicationContext but when i try to run it it crashes, here is the code that makes the application crash
if (!connected.isState()) {
client = new MqttAndroidClient(myContext.context, SERVERURI, CLIENTID);
try {
IMqttToken token = client.connect();
token.setActionCallback(new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
//we are connected
connected.setState(true);
}
@Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
//we are not connected
}
});
} catch (Exception e) {
e.printStackTrace();
}
return;
}
here is the myContext class
class myContext extends Application {
public static Context context;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
} what can i do to fix the problem?