Skip to main content
2 of 2
deleted 32 characters in body; edited tags; edited title
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Loading interstitial adMob in different threads

I want to load Interstitial AdMob after 5 second, after the Activity started, in another Thread. Is this code right, or I'm duplicating Runnables? Is there a better way?

    Handler handler;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setActivityImmersiveMode();
    setContentView(R.layout.activity_normal_mode);


    // loading ads
    handler = new Handler();

    Runnable runnable = new Runnable() {
        @Override
        public void run() {

            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    loadInterstitialAd();
                }
            }, 5000);

        }
    };

    Thread thread = new Thread(runnable);
    thread.setName("AdThread");
    thread.start();
    
}
MohammadL
  • 163
  • 1
  • 1
  • 8