Can i have an example of displaying a toast using runOnUiThread.

So here is the final full code. Thanks to all who have replied.

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends Activity {


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    MainActivity.this.runOnUiThread(new Runnable() {

        public void run() {
            Toast.makeText(MainActivity.this, "This is Toast!!!", Toast.LENGTH_SHORT).show();

        }
    });
}

}

And About the XML, its is the default XML file created. No change needed.

Leave a Comment