views:

84

answers:

2
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Thread thread = new Thread(){
        public void run() {
            try {
                sleep(50);
                Toast toast = Toast.makeText(getApplicationContext(), "Logged In", 100);
                toast.show();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };
    thread.start();
}

This code don't work why?

A: 

I don't really understand what is your target, but your Toast.makeText() 3rd parameter can't be anything other than Toast.LENGTH_LONG or Toast.LENGTH_SHORT.

http://developer.android.com/reference/android/widget/Toast.html#makeText(android.content.Context,%20java.lang.CharSequence,%20int)

Kevin Gaudin
No toast appear anyway
hanswurst
A: 

Why are you trying to Toast on another thread?

Try spawning

Toast.makeText(getApplicationContext(), "Logged In", 10000).show();

directly on the UI thread...

Sotapanna
That's right, and you can use postDelayed() method on a new Handler or on an existing View if you want to wait some time before displaying it.
Kevin Gaudin