Reputation: 674
I have the following code:
protected MyCallback getMyCallbackHandler() {
return new MyCallback() {
@Override
public void onReady() {
// DO STUFF
if (stuff!= null) {
mThread = new MyThread(stuff,MyActivity.this);
mThread.execute(mSensors.getLocation());
}
else {
Toast.makeText(MyActivity.this, "No target detected! Try again later.", Toast.LENGTH_LONG).show();
mSensors.registerCallback(null);
}
runOnUiThread(new Runnable(){
@Override
public void run() {
comp.setVisibility(View.VISIBLE);
}
});
}
};
}
The problem is that if stuff==null
when Toast.makeText(...).show()
is called, first the toast message doesn't appear and second the next lines seems to be not executed.
If I comment just the Toast
line, everything run as expected.
I tried to put as context MyActivity.this
, getParent().getApplicationContext()
and also getApplicationContext()
but it doesn't work.
Upvotes: 0
Views: 139
Reputation: 14199
you can't use Toast
here you should use Log.d()
, if you really want to debug the applications start playing with Logcat !
if you want to use Toast inside this pass context to getMyCallbackHandler(Context c)
and use that in your Toast like
else {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(c, "No target detected! Try again later.",
Toast.LENGTH_LONG).show();
}
});
mSensors.registerCallback(null);
}
Upvotes: 1