1

I created the splash screen as said by the users of stackoverflow, but still not able to get the splash screen for the android app and my code for that is

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);

 // thread for displaying the SplashScreen
    Thread splashTread = new Thread() {
        @Override
        public void run() {
            try {
                int waited = 0;
                boolean active = false;
                while(active && (waited < 1000)) {
                    sleep(100);
                    if(active) {
                        waited += 100;
                    }
                }
            } catch(InterruptedException e) {
                // do nothing
            } finally {
                startActivity(new Intent(SplashScreenActivity.this,MainActivity.class));
                finish();
                //startActivity(new Intent("com.splash.com.MyApps"));
                //startActivity( new Intent(getApplicationContext(), Myapps.class));
            }
        }
    };
    splashTread.start();
}
j0k
  • 22,600
  • 28
  • 79
  • 90

3 Answers3

3

just copy this and changes as per your file modification.

public class Splash extends Activity {

    private final int SPLASH_DISPLAY_LENGHT = 2000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.splashscreen);

        /* New Handler to start the Menu-Activity 
         * and close this Splash-Screen after some seconds.*/
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                /* Create an Intent that will start the Menu-Activity. */
                Intent mainIntent = new Intent(Splash.this,MainActivity.class);
                Splash.this.startActivity(mainIntent);
                Splash.this.finish();
            }
        }, SPLASH_DISPLAY_LENGHT);
    }
ckpatel
  • 1,926
  • 4
  • 18
  • 34
2

do this...

@Override
    protected void onCreate(Bundle savedInstanceState) 
    {   
             mythread thread = new  mythread();
             thread.start();
        }
class mythread extends Thread
    {

        @Override
        public void run()
        {

            super.run();

            try
            {
                Thread.sleep(3000);

                    Intent i = new Intent(Splash_Screen.this,ArboristActivity.class);
                    finish();
                    startActivity(i);

            }
            catch (Exception e) 
            {
                Log.v("log",e.toString());
            }   
        }//End Run

    }

and put the splashScreenActivity in your manifest file as a Launcher Activity...like this..

<activity
            android:name="com.app.Login.Splash_Screen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>
Mehul Ranpara
  • 4,245
  • 2
  • 26
  • 39
  • thank u so much, thats the mistake i had done, now i got the splash screen, but transformation from splash screen to next page is not getting, it is displaying only the splash screen and also imageview is not getting displayed in the splash screen – user1796350 Nov 06 '12 at 12:22
  • i had accepted ur answer:) but stil din get imageview in my splash screen:( – user1796350 Nov 06 '12 at 12:38
  • still not accepted you have to check my answer..when your cursor come down to up vote at that time hoghlighted checkmark there..you have to click on that – Mehul Ranpara Nov 06 '12 at 12:41
1

Because you are initializing your active flag inside the run method with false, it will never enter in the while..it should be like..

boolean active = true;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);

 // thread for displaying the SplashScreen
Thread splashTread = new Thread() {
    @Override
    public void run() {
        try {
            int waited = 0;

            while(active && (waited < 1000)) {
                sleep(100);
                if(active) {
                    waited += 100;
                }
            }
        } catch(InterruptedException e) {
            // do nothing
        } finally {
            startActivity(new Intent(SplashScreenActivity.this,MainActivity.class));
            finish();
            //startActivity(new Intent("com.splash.com.MyApps"));
            //startActivity( new Intent(getApplicationContext(), Myapps.class));
        }
    }
};
splashTread.start();
}
Nermeen
  • 15,883
  • 5
  • 59
  • 72
  • still it directly takes to the main page... splash screen is not getting displayed – user1796350 Nov 06 '12 at 10:27
  • that's depends on setContentView(R.layout.activity_splash_screen); – Nermeen Nov 06 '12 at 10:35
  • SplashScreenActivity must defined as a Launcher in your manifest and the MainActivity as default.. – Nermeen Nov 06 '12 at 10:52
  • thank u so much, now i got the splash screen, but transformation from splash screen to next page is not getting, it is displaying only the splash screen and also imageview is not getting displayed in the splash screen. – user1796350 Nov 06 '12 at 12:22