0

我正在编写一个代码,其中有人点击广告并返回应用程序,广告应该消失。但广告仍然出现。

我的应用程序没有恢复并再次启动,一次又一次地给 toast msg。

我已经 android:launchMode="singleInstance"在清单和
android:alwaysRetainTaskState="true"活动部分添加了。

这是我的 mainactivity .java 文件的代码:

       public class MainActivity extends Activity implements AdListener{

public static int count=0,dispad=0;
public static LinearLayout lay1;
private static final Class<?>[] NUMBERS = {First.class};
 protected AdView adView;
 View admobAds;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    adView = (AdView)findViewById(R.id.ad);

    Toast toast = Toast.makeText(getApplicationContext(), "Click on the ad 
      to    make it disappear" +
                "", Toast.LENGTH_LONG);
        toast.show();

     adView.loadAd(new AdRequest());
         adView.setAdListener(this);

     lay1=(LinearLayout)this.findViewById(R.id.mainlay);

     admobAds = (View) findViewById(R.id.ad);
     //more code..

    public void onDismissScreen(Ad arg0) {

    lay1.removeView(admobAds);
    dispad=1;
    // TODO Auto-generated method stub

}
    }

xml文件如下:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
  android:orientation="vertical"
   tools:context=".MainActivity"
  android:id="@+id/mainlay" 
   >

   <com.google.ads.AdView

     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

    android:id="@+id/ad"
   android:layout_width="fill_parent"
       android:layout_height="wrap_content"

     ads:adUnitId="a1512c9e4ddb675"
     ads:adSize="SMART_BANNER"

   ads:loadAdOnCreate="true"
 />

        // more linear layouts.

显现 :

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ash"
 android:launchMode="singleInstance"
android:versionCode="2"
android:versionName="1.1" 
android:installLocation="auto"


>


<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <meta-data android:value="true" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" />


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.ashsoft.basiccprogram.MainActivity"
        android:label="@string/app_name" 
         android:alwaysRetainTaskState="true"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

     <activity
        android:name="com.ashsoft.basiccprogram.First"
        android:label="Program code"
    >
        <intent-filter>
            <action android:name="android.intent.action.FIRST" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>


<activity android:name="com.google.ads.AdActivity"

   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|s        mallestScreenSize"/>

</application>

   </manifest>

我不知道我要去哪里错了。

4

0 回答 0