Java Libgdx。当我退出游戏时,admob仍在工作

Java Libgdx。当我退出游戏时,admob仍在工作,java,android,libgdx,admob,Java,Android,Libgdx,Admob,我对admob有意见。Admob工作正常,但当我退出游戏时,Admob仍在工作。我做错了什么?请帮帮我 即使我退出游戏,在日志中我看到admob仍在工作 AndroidLuncher.java public class AndroidLauncher extends AndroidApplication { private AdView adView; private static final String AD_UNIT_ID = "xxxxxxxxxxxxxxxxxxxxxxx"; @

我对admob有意见。Admob工作正常,但当我退出游戏时,Admob仍在工作。我做错了什么?请帮帮我

即使我退出游戏,在日志中我看到admob仍在工作

AndroidLuncher.java

public class AndroidLauncher extends AndroidApplication {

private AdView adView;
private static final String AD_UNIT_ID = "xxxxxxxxxxxxxxxxxxxxxxx";


@Override
protected void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
         cfg.useWakelock = true;
         cfg.useAccelerometer = false;
         cfg.useCompass = false;


         // Create the layout
         RelativeLayout layout = new RelativeLayout(this);

         // Do the stuff that initialize() would do for you
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
         getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

         // Create the libgdx View
         View gameView = initializeForView(new MyGameStart(), cfg);

         // Add the libGDX view
         layout.addView(gameView);

         // Create and setup the AdMob view
         AdView adView = new AdView(this);
         adView.setAdSize(AdSize.SMART_BANNER);
         adView.setAdUnitId(AD_UNIT_ID);

         AdRequest adRequest = new AdRequest.Builder()
         .addTestDevice("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
         .build();

         // Add the AdMob view
         RelativeLayout.LayoutParams adParams = 
             new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                     RelativeLayout.LayoutParams.WRAP_CONTENT);
         adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
         adParams.addRule(RelativeLayout.CENTER_IN_PARENT);

         adView.loadAd(adRequest);
         layout.addView(adView, adParams);

         // Hook it all up
         setContentView(layout);



}
  @Override
    public void onResume() {
      super.onResume();
      if (adView != null) {
        adView.resume();
      }
    }

    @Override
    public void onPause() {
      if (adView != null) {
        adView.pause();
      }
      super.onPause();
    }


    @Override
    public void onDestroy() {
      // Destroy the AdView.
      if (adView != null) {
        adView.destroy();

      }
      super.onDestroy();
    } }
main.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
     <com.google.android.gms.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="xxxxxxxxxxxxxxxxxxxxxx"
                         ads:adSize="SMART_BANNER"/>
</LinearLayout>
AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="pl.com.test.testgame.android"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />
    <!-- Include required permissions for Google Mobile Ads to run-->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/GdxTheme" >

         <!--This meta-data tag is required to use Google Play Services.-->
        <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

        <activity
            android:name="pl.com.test.testgame.android.AndroidLauncher"
            android:label="@string/app_name" 
            android:screenOrientation="landscape"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!--Include the AdActivity configChanges and theme. -->
        <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>

02-13 14:58:55.271: I/Ads(2604): Starting ad request.
02-13 14:58:56.111:I/Ads2604:计划从现在起60000毫秒后的ad刷新。 02-13 14:58:56.111:I/Ads2604:Ad已完成加载

退出游戏

02-13 14:59:56.121:I/Ads2604:正在启动ad请求。 02-13 14:59:56.931:I/Ads2604:计划从现在起60000毫秒后的ad刷新。
02-13 14:59:56.931:I/Ads2604:Ad已完成加载。

创建一个onStop方法并在那里停止adMob。

尝试将AdView实例设置为NULL,并将其保留在那里,以便GC处理。它可能会出现NullPointerException,因此请确保您能够处理它。

我解决了这个问题。 我有两次Adview Adview

public class AndroidLauncher extends AndroidApplication {

private AdView adView;

@Override
protected void onCreate (Bundle savedInstanceState) {

                       ***

         // Create and setup the AdMob view
         AdView adView = new AdView(this);

                       ***

当我删除一个时,AdMob工作正常。

您提到,您在日志中看到AdMob仍在运行。你能发布这些日志吗?请将其标记为正确,这样我们就知道问题已经解决。当我单击“接受此答案”时。。。我知道你明天可以接受你自己的答案。对不起,我不能标记这个问题已经解决/