I have a class that implements two interfaces : OnClickListener and Runnable
When the user presses a button I will go in a Switch like this:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
pd = ProgressDialog.show(this, "Please Wait",
"Generating", false);
Thread t = new Thread(this);
t.start();
break;
}
}
This should start my Run-method, which has an else-statement like this:
else {
Message msg = handler.obtainMessage();
msg.obj = "1";
handler.sendMessage(msg);
}
And my handler method:
private Handler handler = new Handler() {
@SuppressWarnings("unchecked")
@Override
public void handleMessage(Message m) {
pd.dismiss();
if(m.toString().equals("1")) {
Toast.makeText(getApplicationContext(), "Do a scan first", Toast.LENGTH_SHORT).show();
}
}
};
The code runs without any exception, but the Toast is not showed, it should be! I am sure that people will say that I should use an AsyncTask for this, but thats not the answer that I am looking for.
What am I doing wrong here?
You have to retrive the object inside the message: