Interstitial添加没有得到加载在Android

问题描述:

调试后,我发现我的onLoaded()返回是错误的,只有一个空白的白色屏幕出现。 没有添加正在加载!即使我等待无限时间 附加单元ID是Interstitial添加没有得到加载在Android

https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial 回升(样品加) 这里是我的MainActivity类别

package com.example.jatinarora.threestickhockey; 
    import android.app.ActionBar; 
    import android.content.Context; 
    import android.content.SharedPreferences; 
    import android.graphics.Bitmap; 
    import android.graphics.BitmapFactory; 
    import android.graphics.Canvas; 
    import android.graphics.Paint; 
    import android.media.MediaPlayer; 
    import android.os.SystemClock; 
    import android.support.v4.view.MotionEventCompat; 
    import android.support.v4.view.VelocityTrackerCompat; 
    import android.support.v7.app.ActionBarActivity; 
    import android.os.Bundle; 
    import android.util.DisplayMetrics; 
    import android.util.Log; 
    import android.view.Menu; 
    import android.view.MenuItem; 
    import android.view.MotionEvent; 
    import android.view.VelocityTracker; 
    import android.view.View; 
    import android.view.ViewGroup; 
    import android.view.Window; 
    import android.view.WindowManager; 
    import android.widget.Toast; 
    import com.google.android.gms.ads.AdListener; 
    import com.google.android.gms.ads.AdRequest; 
    import com.google.android.gms.ads.AdView; 
    import com.google.android.gms.ads.InterstitialAd; 

    public class MainActivity extends ActionBarActivity { 

public InterstitialAd interstitial; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_main); 
    WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    interstitial = new InterstitialAd(this); 
    interstitial.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); 
    requestNewInterstitial(); 
    float count123 = 1 ; 
    // i tried setting the loop to infinity to wait for the advertisment to load! 
    while(count123 >=0) { 
     if (interstitial!= null && interstitial.isLoaded()) { 
      interstitial.show(); 
      count123 = -1; 
     } 
     } 
     } 

private void requestNewInterstitial() { 
    AdRequest adRequest = new AdRequest.Builder().build(); 
    interstitial.loadAd(adRequest); 
} 



@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    //getMenuInflater().inflate(R.menu.menu_main, menu); 
    return true; 
} 
@Override 
protected void onResume() { 
    super.onResume(); 
    mView.running = true; 
} 
protected void onPause() 
{ 
    mView.resume = 1; 
    mView.running = false; 
    super.onPause(); 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
}} 

在我activity_main.xml我没加的AdView因为在所有的教程,我已经访问的链接,我还没有看到任何的间隙,它被用于横幅

这里是我的activity_main.xml中

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingLeft="0dp" 
android:label="@string/app_name" 
android:paddingRight="0dp" 
android:paddingTop="0dp" 
android:paddingBottom="0dp" tools:context=".MainActivity"> 
<com.example.jatinarora.threestickhockey.mView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    /> 
    </RelativeLayout> 

这里是我的manifest资源配置文件

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.jatinarora.threestickhockey" > 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"> 
     <activity 
     android:name=".MainActivity" 
     android:screenOrientation="portrait" 
     android:label="@string/app_name" > 

     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <meta-data android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version"/> 
    <activity android:name="com.google.android.gms.ads.AdActivity" 
       android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
     android:theme="@android:style/Theme.Translucent" /> 
    </application> 
</manifest> 

任何建议,错误为什么加没有显示出来或任何其他的解决办法将有助于很多!

+0

为什么不使用布尔值run = true;在你的while循环中,多数民众赞成只是顺便说一句,也是空白的白色屏幕,你的应用程序屏幕或它在你的应用程序的顶部?如果你的应用程序显示一个白色屏幕,然后它的你的应用程序,而不是admob – Elltz 2015-04-02 19:15:44

+0

看到,如果我只运行我的应用程序没有admob,它鞋3-4秒的白色屏幕,然后工作正常! :D ..即使我使用有限的while循环,那么也是我的应用程序工作..和插页式添加不显示! ..等待加载得到加载我做了循环等待,直到添加出现! – 2015-04-03 02:03:00

+0

任何答复先生? – Elltz 2015-04-17 18:28:25

[问题的原因]

我不能给出一个准确的原因的问题,但是,在主线程上运行的循环引入滞后,这就是之所以加不加载,因为它超时如此之快,并没有空间,因为你在该线程上有大量的进程占用工作,这也可能是白屏3-4秒的原因..但除此之外,添加不显示一般可能可能是您的互联网连接或.......

所以,先生,忘了循环,检查这个answer,它会告诉你如何显示t他在加载完成时添加 - 它有onAdLoaded(),当interstitial.isLoaded()为真时触发,而不是始终循环。而其余的你将它保留到互联网和谷歌,添加将显示出来,当它出现时,你可以添加断点以知道它如何下降