I test the following code and the Toast message did not appear and the "TestMethod" did not call "Catch" method , please help me ?
public void TestMethod()
{
Test= new Thread(new Runnable() {
public void run() {
try{
Catch();
}
catch (Exception ioe)
{
}
}
});
Test.start();
}
public void Catch()
{
Test2= new Thread(new Runnable() {
public void run() {
try{
Toast.makeText(getApplicationContext(), "Yes", Toast.LENGTH_SHORT).show();
}
catch (Exception ioe)
{
}
}
});
Test2.start();
}
May be runOnUiThread helpful to you.
Try this:
runOnUiThread(new Runnable()
{
public void run()
{
Toast.makeText(getApplicationContext(), "Yes", Toast.LENGTH_SHORT).show();
}
});
You should call Toast.makeText
on UI thread. Read this for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With