user65721
user65721

Reputation: 2923

How to show a fragment for a few second and hide it?

I want to implement a fragment as a splash screen, it will be shown for less than 1 second and it will replace itself with an interstitial ad. I want to implement Admob's suggested way of showing interstitial ads. I want to display 'App Loading' screen inside a fragment and hide the fragment when ad is ready. I am doing it inside a fragment instead of a view becuase I need to make this a generic solution and then add it to the my other apps as well.

Example from Admob

Upvotes: 2

Views: 1617

Answers (2)

Vivek Pratap Singh
Vivek Pratap Singh

Reputation: 1662

Try this code

new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                // your code here
            }
        }, TIME_OUT_IN_MILLIS);

Upvotes: 2

Lorenzo Vincenzi
Lorenzo Vincenzi

Reputation: 1212

Into the onCreate of your Interstitial ad put this code

// This time is in milliseconds
final int SPLASH_TIME_OUT = 3000;

new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                // Code to start new activity and finish this one
            }
        }, SPLASH_TIME_OUT);

Upvotes: 2

Related Questions