I am new to android i am trying to create a new thread to invoke another method.
But don’t why it is throwing the error.
here is my stub
void test()
{
int i=0;
Toast.makeText(getApplicationContext(), "Testing", Toast.LENGTH_SHORT).show();
}
public void Button2_Click(View v)
{
Thread thread = new Thread()
{
@Override
public void run() {
test();
}
};
thread.start();
}
You can’t manipulate the UI from other threads than the main thread, and launching a Toast involves the user interface.
change your test function
now if the thread works you will se a log inside LogCat. If you want to display a Toast from another thread, you must use Handler or runOnUiThread.