加载非页内广告之前如何通知用户

当前,在我的应用程序中,当用户单击按钮或移至新活动时,我正在显示广告,我要做的是在加载广告之前通知用户。我想显示类似广告正在加载...!之类的消息,并且2-3秒后,味精应该消失了。简而言之,我想显示有关广告预载的对话框。我在警报msg的帮助下尝试了此操作,但是该方法不起作用,我不确定我们需要在哪里添加警报对话框。

请帮助...!

预先感谢...!

jelly19870212 回答:加载非页内广告之前如何通知用户

您可以使用Thread倒数x秒,textView每秒钟改变一次(这将是一个数字),然后用户会感觉倒数

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()
}

在您的活动中:

1)您需要实现CountDownListener(当实现CountDownListener时,您将必须实现onCountDownThreadDone()方法,在那里您需要实现dailog box)。
2)此外,您需要致电CountDownThread(3,this)3是您的显示时间,以秒为单位,this是您的侦听器)。

这是interface

public interface CountDownListener {
    void onCountDownThreadDone();
}

递减计数(在您的情况下为3秒)完成后,将调用onCountDownThreadDone()方法(请查看run()类中的CountDownThread方法)。然后将显示dailog box的实现(您在Activity中实现)。

,

您可以按以下方式使用CountDownTimer,首先,显示Toast消息,然后显示3秒钟(3000毫秒),然后您的广告代码将开始投放

        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();
,

我通过使用以下代码实现了

/* 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);
本文链接:https://www.f2er.com/2782795.html

大家都在问