2015-11-04 99 views
1

我想實現一個片段作爲啓動畫面,它會顯示不到1秒,它會用自己的插頁式廣告取而代之。我想實施Admob建議的展示插頁式廣告的方式。我希望在片段內顯示'應用加載'屏幕,並在廣告準備就緒時隱藏片段。我正在做一個片段而不是一個視圖,因爲我需要使這個通用的解決方案,然後將其添加到我的其他應用程序以及。如何顯示片段幾秒鐘並隱藏它?

Example from Admob

+1

無關,但這是一個強大的卸載驅動程序,你在做什麼。 – njzk2

回答

2

進入您的插頁式廣告的OnCreate把這段代碼

// 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); 
2

您可以顯示一個片段和您的片段交易後,您可以添加

private static int SPLASH_TIME_OUT = 3000; 

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

試試這個代碼

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