首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在android应用程序中,如何在某个时间间隔内或不同的活动中调用广告群广告?

在android应用程序中,如何在某个时间间隔内或不同的活动中调用广告群广告?
EN

Stack Overflow用户
提问于 2014-02-01 05:41:56
回答 1查看 745关注 0票数 0

我在我的应用程序中使用广告群广告,它总是在我的应用程序启动时显示,但是我想在用户退出应用程序时显示这个广告,并返回到主要的活动调用,这样它在我的应用程序中是如何实现的。

我的代码是

代码语言:javascript
复制
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        interstitial = new InterstitialAd(this, "a152eb628a493d8");

        adRequest = new AdRequest();

        interstitial.loadAd(adRequest);

        interstitial.setAdListener(this);





        web=(WebView)findViewById(R.id.webview);
        web.getSettings().setJavaScriptEnabled(true);
        web.setWebViewClient(new WebViewClient());
        web.getSettings().setBuiltInZoomControls(true);
        web.loadUrl("http://dcs-dof.gujarat.gov.in/live-info.htm");



    }




    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        menu.add(0,1,Menu.NONE,"About");
        menu.add(0,2,Menu.NONE,"Feedback");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id=item.getItemId();
        if(id == 1)
        {

            Toast.makeText(MainActivity2.this,"About",Toast.LENGTH_LONG).show();

            Intent i=new Intent(MainActivity2.this,about.class);
            startActivity(i);
         }
        else {

            Toast.makeText(MainActivity2.this,"Feedback",Toast.LENGTH_LONG).show();

            Intent i2 =new Intent(MainActivity2.this,feedback.class);
            startActivity(i2);
        }
        return super.onOptionsItemSelected(item);
    }


    private boolean doubleBackToExitPressedOnce = false;

    @Override
    protected void onResume() {

        //interstitial.loadAd(adRequest);
        super.onResume();

        this.doubleBackToExitPressedOnce = false;
    }

    @Override
    public void onBackPressed() {
          if (doubleBackToExitPressedOnce) {
            super.onBackPressed();
            return;
        }
        this.doubleBackToExitPressedOnce = true;
        Toast.makeText(this,"Press Again to Exit", Toast.LENGTH_SHORT).show();
    }




    @Override
    public void onDismissScreen(Ad ad) {
        // TODO Auto-generated method stub


    }




    @Override
    public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
        // TODO Auto-generated method stub

    }




    @Override
    public void onLeaveApplication(Ad arg0) {
        // TODO Auto-generated method stub

    }




    @Override
    public void onPresentScreen(Ad arg0) {
        // TODO Auto-generated method stub

    }




    @Override
    public void onReceiveAd(Ad ad) {
        Log.d("OK", "Received ad");
        if (ad == interstitial) {
          interstitial.show();

    }

    }

    @Override
    protected void onRestart() {
        // TODO Auto-generated method stub


//      interstitial.loadAd(adRequest);
        super.onRestart();
    }
    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
    //  interstitial.loadAd(adRequest);
        super.onStart();
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub

        //interstitial.loadAd(adRequest);
        super.onDestroy();
    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        //interstitial.loadAd(adRequest);   
        super.onStop();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
//      interstitial.loadAd(adRequest);
        super.onPause();
    }
EN

回答 1

Stack Overflow用户

发布于 2014-02-02 01:28:28

您真的不想尝试在退出您的Actvity时向用户显示广告,这是一个糟糕的用户体验。

即使你确实精心设计了一种方法来获取广告,并在你的活动被破坏之前呈现,你也不知道要多长时间才能找回广告,这样你的活动可能会在退出时挂几秒钟。用户讨厌这种东西。

I强烈建议您在应用程序中找到另一个显示广告的位置。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21494584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档