2

I would like to do a simple splash screen for my Android Wear game. I have read up on How do I make a splash screen?

However, when the splash activity launch the intent and quit, you will see the watch face for a second, before the main activity swipe in from right.

Although this is a minor issue, I would like to know whether the transition can be seamless. It is best not to see the watch face (while splash activity quit), and will be nice if there is no swipe in from right animation of the main activity. I see some Android Wear games implement the splash screen properly.

My Splash code:

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.splash);

    new Handler().postDelayed(new Runnable(){
        @Override
        public void run() {
            Intent mainIntent = new Intent(Splash.this, Invaders.class);
            mainIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            Splash.this.startActivity(mainIntent);
            Splash.this.finish();
        }
    }, SPLASH_DISPLAY_LENGTH);
}

PS: I have also tried the other suggestion in the link to just use a custom splash theme but it does not seem to work.

Community
  • 1
  • 1
Lim Thye Chean
  • 8,704
  • 9
  • 49
  • 88
  • i would suggest rather launching a new activity, just call the setContentView method with different layout..hope this resolves the issue.. – Vny Kumar Jan 06 '15 at 11:43
  • Also try a custom animation or disable the animations of the activity transition – Jasper van de Klundert Jan 06 '15 at 12:21
  • The animation can be switch off (I use overridePendingTransition(0, 0)) but the 1/2 second show of the watch screen between transition still bothers me. – Lim Thye Chean Jan 06 '15 at 12:58
  • Hi @VnyKumar, thanks for suggestion. The problem is the game has been completed, so adding a new splash screen activity before the main activity is easy. It is not just a new layout. – Lim Thye Chean Jan 06 '15 at 13:00

1 Answers1

0

can you try this code ?

// Create a new event for the activity.
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    // Set the layout for the content view.
    setContentView(R.layout.main_activity)

    // Set up an OnPreDrawListener to the root view.
    val content: View = findViewById(android.R.id.content)
    content.viewTreeObserver.addOnPreDrawListener(
        object : ViewTreeObserver.OnPreDrawListener {
            override fun onPreDraw(): Boolean {
                // Check if the initial data is ready.
                return if (viewModel.isReady) {
                    // The content is ready; start drawing.
                    content.viewTreeObserver.removeOnPreDrawListener(this)
                    true
                } else {
                    // The content is not ready; suspend.
                    false
                }
            }
        }
    )
}
hong developer
  • 13,291
  • 4
  • 38
  • 68