调试后我发现我的onLoaded()
返回为假,只显示空白屏幕。
没有添加加载!即使我等待无限的时间
从
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>
这是我的manifestFile
<?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 :(得分:0)
[问题的原因]
我无法给出问题的确切原因,但是,主线程上的运行循环引入滞后,这就是为什么加载没有加载的原因因为它超时这么快而且没有空间,因为你在这个线程上有很多进程占用工作,这也可能是白屏3-4秒的原因..但除此之外,添加不显示通常可能是你的互联网连接或。 ......
所以先生,忘了循环,检查这个answer,它会告诉你如何在加载完成后显示添加 - 它有onAdLoaded()
,当interstitial.isLoaded()
是{{1}}时触发是的,而不是一直循环播放..而其余的你把它留给互联网和谷歌,添加会在它出现时显示,你可以添加断点来了解它如何下降