Lim Thye Chean
Lim Thye Chean

Reputation: 9434

Making a splash screen on Android Wear

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.

Upvotes: 2

Views: 1642

Answers (1)

hong developer
hong developer

Reputation: 13926

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
                }
            }
        }
    )
}

Upvotes: 0

Related Questions