-1

Possible Duplicate:
How do I make a splash screen in android

Can any one tell me what is the simplest and most elegant way to create splash screen on android . I have seen many hackish way using timers (google search) etc.... Surely thats not elegant way?

Community
  • 1
  • 1
codejunkie
  • 1,122
  • 3
  • 13
  • 29
  • By timers you mean "handler.postDelayed()"? – aromero Dec 29 '11 at 01:41
  • yep i been told to avoid handler / threads way of doing it. – codejunkie Dec 29 '11 at 18:34
  • Avoid using why, just cause you were told doesn't make this true...investigate the reason why I use that method extensively on each app, I have never had an issue with it yet. – JPM Dec 30 '11 at 05:15
  • Check my optimal and easy solution: https://medium.com/@vatani.ahmad/android-optimal-splash-screen-without-extra-activity-or-fragment-b60fea45a0cc – Ahmad Vatani May 01 '20 at 10:16

2 Answers2

0

I can't comment, so I'm posting this as an answer.

I'm not sure using SplashScreen is elegant at all. As already stated in similar question, you should use splashscreen if there is some background work that has to be done before showing user a GUI. If it's not necessary in your case, just make your app available for user's enjoyment as soon as possible.

Community
  • 1
  • 1
beam022
  • 1,793
  • 4
  • 20
  • 27
  • Yes google gave me similar option it has tendency of going into infinite loop. Im keen to see dialog based solutions or something better. – codejunkie Dec 29 '11 at 01:22
  • I edited my answer, it doesn't make much sense now. Anyway, do you have something like [that](http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/) in mind? – beam022 Dec 29 '11 at 01:34
  • Nope, again while loop not good idea. – codejunkie Dec 29 '11 at 01:36
  • Have you checked [last comment](http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/comment-page-2/#comment-25665)? It mentions using android animation as a splashscreen. Also, did you check the accepted answer on [the other question posted on SO](http://stackoverflow.com/questions/5486789/how-do-i-make-a-splash-screen-in-android)? And [this one](http://stackoverflow.com/questions/1979524/android-splashscreen)? – beam022 Dec 29 '11 at 01:45
0

This is what I use, my MainActivity

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;

public class mainActivity extends Activity {
/** Called when the activity is first created. */

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.splash);

    Thread lTimer = new Thread() {

        public void run() {

            try {
                int lTimer1 = 0;
                while (lTimer1 < 2000) {
                    sleep(100);
                    lTimer1 = lTimer1 + 100;
                }
                startActivity(new Intent("com.examples.MENU"));
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            finally {
                finish();
            }
        }
    };
    lTimer.start();
}

}

Which uses splash.xml where I add my splash image, then calls my Menu class. change (lTimer1 < 2000) to however long you want it to appear, 1000 = 1 second.

Bill Gary
  • 2,987
  • 2
  • 15
  • 19
  • i found solution posted on this blog to be much elegant solution. http://blog.iangclifton.com/2011/01/01/android-splash-screens-done-right/ – codejunkie Dec 29 '11 at 16:00