1

i need to show the ad before the activity show the ui, so I need to set a delay (5 secs more or less), in that time I need to test if ad is ready, and eventually show it, after 5 secs, the activity need to show the ui in all case.

I have tried this :

Handler handler = new Handler(); 
handler.postDelayed(new Runnable() {
       public void run() {
            ricevuto = 1;
            }
        }, 6000);

do {interstitial.show();}
while (ricevuto == 0);

but it loop forever.

StarsSky
  • 6,721
  • 6
  • 38
  • 63
Vulneraria
  • 139
  • 1
  • 9

2 Answers2

3

Change your code to:

handler.postDelayed(new Runnable() {
       public void run() {
         interstitial.show();
       }
   }, 6000);
William
  • 20,150
  • 8
  • 49
  • 91
0

Instead of the busy wait you do with the while loop, you could use the handler postMessageDelayed function to get the delay effect. Simply implement the handle message method of the handler and place the code of starting the UI there.

For more details, check the docs:

http://developer.android.com/reference/android/os/Handler. html

chipopo
  • 326
  • 2
  • 9