1

I have a SplashScreen activity at my android app that lasts for 3 seconds, and then it switches to MainActivity.

MainActivity plays a sound, and it has a button. My problem is that the sound plays when the SplashScreen activity is visible.

onResume at MainActivity calls for run(), run() sleeps for 2 seconds and plays the sound.

public void run() {

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    m.start();

    try {
        Thread.sleep((int) randomValue * 1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    m.seekTo(0);

    m.start();
    cpu.setText(EranThatWillShortYourDouble(randomValue));

    btn.setClickable(true);

}

@Override
protected void onResume() {
    super.onResume();
    run();
}

Instead of SplashScreen displaying for 3 seconds and switches to MainAcivity, It lasts 5 seconds and plays the sound when SplashScreen is visible.

What do I do?

EDIT: This is my SplashScreen activity:

public class SplashScreen extends Activity {

private static int SPLASH_TIME_OUT = 3000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);
    new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(SplashScreen.this, MainActivity.class);
            startActivity(i);

            // close this activity
            finish();
        }
    }, SPLASH_TIME_OUT);
}

}

2 Answers2

1

Do not use splash screens in Android. They are against the design guidelines and provide a poor UX.

http://developer.android.com/design/patterns/help.html#your-app

Mark Buikema
  • 2,483
  • 30
  • 53
  • Is there anything else that displays the logo while loading the app? – Machlev Development May 09 '14 at 17:24
  • 2
    I disagree with Google in this one. If you don't NEED to display a SplashScreen, then that's fine, but if you need to load resources before you app is functional (there are plenty of examples) then they are perfectly valid. In fact, the very same Google Maps SHOULD have one, instead it displays a lame blank screen (#f5f5f5 background) for about a second (on a Nexus 5). The rule is, don't display a splash screen just to show a logo. Users will rather use your app faster than look at the logo, *unless* you need to do stuff and need your users to wait in the mean time. – Martin Marconcini May 09 '14 at 17:27
  • No, bring your user directly to the application and show a loading progressbar inside your app. Splash screens totally ruin the UX. If you want to show your branding logo and colors to the users, style the action bar according to your brand. – Mark Buikema May 09 '14 at 17:30
  • 1
    I still don't agree. Some APIs/Architectural designs don't fit in that pattern. Bringing the user to an app they can't use with a progressbar doesn't always translate in a good or better design. Don't show useless splash screens? (like the above) yes, I agree! NEVER show Splashscreens? no way, app design is more than black and white. – Martin Marconcini May 09 '14 at 17:35
  • What do you mean by app design is more than black and white? There are plenty of ways to show your logo's and colors inside your app. When the user is taken directly to the app he instantly gets an idea how the app works and can quickly navigate to other sections even if the data hasn't loaded yet. I recommend watching Android Design in Action, they are really helpful in making design decisions in Android and it's fun to create your app according to the guidelines so you can be sure your app is constructed properly. https://www.youtube.com/watch?v=pEGWcMTxs3I – Mark Buikema May 09 '14 at 17:41
1

Please take a look at AsyncTasks, Android Runnables and the ability to use a Handler to postDelayed.

Don't do thread.sleep in the main thread, it's really bad. :)

Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144
  • What can I use to make the app wait? – Machlev Development May 09 '14 at 17:25
  • 1
    Why do you want the app to wait?! The users will have to wait five seconds before using your app for what reason? (3 of the splashscreen + 2 of that thread sleep) PLUS some random value you have there… it doesn't make sense. – Martin Marconcini May 09 '14 at 17:30
  • Just to show my logo. Is there any alternative to Thread.sleep? – Machlev Development May 09 '14 at 17:32
  • 1
    "Just to show my logo." Users won't care about your logo the 2nd time they open the app. Seems like you do not need a splashscreen. Don't use one. Provide an About menu where you show a nice image of your logo. You don't need to SLEEP the app, let the users start using it as soon as possible! – Martin Marconcini May 09 '14 at 17:36