Magic due to Logic
Magic due to Logic

Reputation: 121

How to notify user before loading Interstitial Ad

Currently in my application I am showing ad when user click on button or move to new activity, what I want to do is notify user before loading ad. I want to show message like Ad is loading...! and after 2-3 sec that msg should disappear. In short I want to show dialog on preload of ad. I was trying this with help of alert msg but that is not working, I am not sure where we need to add alert dialog.

Please help...!

Thanks in Advance...!

Upvotes: 0

Views: 1079

Answers (3)

Magic due to Logic
Magic due to Logic

Reputation: 121

I achieved this by using following code

/* Show your dialog */

    ShowDailog();

/* following code will run after 3000ms */

    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            showInterstitial();
                        }

                    }, 3000);

Upvotes: 0

Evyatar Cohen
Evyatar Cohen

Reputation: 342

You can use a Thread that count down for x sec, every sec the textView will change (it will be a number) and then the user will get the feeling of counts down

public CountDownThread extend Thread { 

private int mTotalNum;
private CountDownListener mCuntDownListener;


public CountDownThread(int totalNum, CountDownListener countDownListener) {
   this.mTotalNum = totalNum
   this.mCountDownListener = countDownListener
}

@Override
public void run(){
  while (mTotalNum > 0) {
      try {
        sleep(1000);
      }catch (InterruptedException e){
     //
      }
      --mTotalNum
   } 
  mCuntDownListener.onCountDownThreadDone()
}

In your activity:

1) You need to implement CountDownListener (When you implement the CountDownListener you will have to implement the onCountDownThreadDone() method, there you need to implement your dailog box).
2) In addition, you will need to call to CountDownThread(3, this) (3 is your display time in sec, this is the listener).

This is the interface:

public interface CountDownListener {
    void onCountDownThreadDone();
}

After the count down (in your case 3 sec) is finished, the onCountDownThreadDone() method will be called (look at run() method in CountDownThread class). Then the implementation of your dailog box will appear (you implement it in your Activity).

Upvotes: 1

Sinan Ceylan
Sinan Ceylan

Reputation: 1073

You can use a CountDownTimer as below, First, toast message show up then 3 sec.(3000msec) later your ad code will run

        Toast.makeText(this, "Ad is loading...", Toast.LENGTH_LONG).show();

        new CountDownTimer(3000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {  // runs after 2 sec. (2000 msec.)
                // This is the place where you call your interstitial ad.
            }
        }.start();

Upvotes: 1

Related Questions