1

I am trying to wait untill the spalsh screen will be over abd then when get the result from splash go to anther activity bu my code not wating for splash (AsyncTask) just going for what after to intent. Hope you can help.

 lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            String nextActivity=new String();
            Thread splashTread = new Thread() {
                @Override
                public void run() {
                    try {
                        splash  splash=(tools.splash) new splash(first.this).execute();
                        int waited = 0;
                        while(splash.running && (waited< getResources().getInteger(R.integer.splashTimeOut)))
                        {
                            sleep(100);
                            if(splash.running) {
                                waited += 100;
                            }
                            // nextActivity=splash.newActivity;
                        }
                        Intent intent = new Intent(first.this,Class.forName("activities.third"));
                     startActivity(intent);
                    } catch(InterruptedException e) {
                        // do nothing
                    } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        finish();

                    }
                }
            };
            splashTread.start();


            try {
                Intent intent = new Intent(first.this,Class.forName("activities.third"));
                 startActivity(intent);
Vitaly Menchikovsky
  • 7,684
  • 17
  • 57
  • 89

1 Answers1

0

Use this code

 Intent intent = new Intent(first.this,Class.forName("activities.third"));
                 startActivity(intent);

inside finally before finish() instead of start try block;

Shalini
  • 1,733
  • 4
  • 17
  • 31
  • I get an error 09-26 08:44:14.738: E/AndroidRuntime(332): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() I think because the AsyncTask have an gui – Vitaly Menchikovsky Sep 26 '12 at 10:13
  • 1
    then use UIthread. Refer this http://stackoverflow.com/questions/6213538/cant-create-handler-inside-thread-that-has-not-called-looper-prepare – Shalini Sep 26 '12 at 10:39