如何添加或忽略Admob的广告AdActivity在Android中?广告、Admob、Android、AdActivity

2023-09-12 05:58:06 作者:゛迩所谓的单纯莪早已看透

我有一个要求,添加或忽略 AdActivity Admob的的广告。我使用的是 TabActivity 的标签内导航的活动都保持在一个的ArrayList 。经过整合,而不是回来了previous活动(即发生整合广告前)我来了应用​​程序的广告,当我浏览到第3活动的选项卡,然后回到$​​ P $ PSS。同时加入了活动的的ArrayList 我设置的意图标志作为 FLAG_ACTIVITY_CLEAR_TOP 。你能告诉我怎样才能克服出来背preSS应用程序中的第三个活动,而是能够来到第二活动,然后到第1 活动

感谢你。

编辑:

  04-10 13:19:32.519:E / AndroidRuntime(1392):致命异常:主要
04-10 13:19:32.519:E / AndroidRuntime(1392):java.lang.RuntimeException的:无法启动的活动ComponentInfo {com.example.admob / com.example.admob.activity.MainTabActivity}:显示java.lang.NullPointerException
04-10 13:19:32.519:E / AndroidRuntime(1392):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-10 13:19:32.519:E / AndroidRuntime(1392):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-10 13:19:32.519:E / AndroidRuntime(1392):在android.app.ActivityThread.access $ 600(ActivityThread.java:123)
04-10 13:19:32.519:E / AndroidRuntime(1392):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1147)
04-10 13:19:32.519:E / AndroidRuntime(1392):在android.os.Handler.dispatchMessage(Handler.java:99)
04-10 13:19:32.519:E / AndroidRuntime(1392):在android.os.Looper.loop(Looper.java:137)
04-10 13:19:32.519:E / AndroidRuntime(1392):在android.app.ActivityThread.main(ActivityThread.java:4424)
04-10 13:19:32.519:E / AndroidRuntime(1392):在java.lang.reflect.Method.invokeNative(本机方法)
04-10 13:19:32.519:E / AndroidRuntime(1392):在java.lang.reflect.Method.invoke(Method.java:511)
04-10 13:19:32.519:E / AndroidRuntime(1392):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784)
04-10 13:19:32.519:E / AndroidRuntime(1392):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-10 13:19:32.519:E / AndroidRuntime(1392):在dalvik.system.NativeStart.main(本机方法)
04-10 13:19:32.519:E / AndroidRuntime(1392):由:显示java.lang.NullPointerException
04-10 13:19:32.519:E / AndroidRuntime(1392):在android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:101)
04-10 13:19:32.519:E / AndroidRuntime(1392):在com.google.ads.AdView< INIT>(的SourceFile:87)。
04-10 13:19:32.519:E / AndroidRuntime(1392):在com.google.ads.doubleclick.DfpAdView< INIT>(的SourceFile:27)。
04-10 13:19:32.519:E / AndroidRuntime(1392):在com.example.admob.activity.MainTabActivity.onCreate(MainTabActivity.java:80)
04-10 13:19:32.519:E / AndroidRuntime(1392):在android.app.Activity.performCreate(Activity.java:4465)
04-10 13:19:32.519:E / AndroidRuntime(1392):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-10 13:19:32.519:E / AndroidRuntime(1392):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-10 13:19:32.519:E / AndroidRuntime(1392):11 ...更多
 

解决方案

我终于找到了它的解决方案!的问题是与布局。因此,我改变了它和它的工作。以下是我的xml code:

 < XML版本=1.0编码=UTF-8&GT?;
< TabHost的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:广告=htt​​p://schemas.android.com/apk/lib/com.google.ads
机器人:ID =@机器人:ID / tabhost
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>

<的FrameLayout
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>

    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=垂直>

        < TabWidget
            机器人:ID =@机器人:ID /标签
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginTop =50dip/>

        <的FrameLayout
            机器人:ID =@机器人:ID / tabcontent
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT/>
    < / LinearLayout中>

    < RelativeLayout的
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT>

        < com.google.ads.doubleclick.DfpAdView
            机器人:ID =@ + ID / AD浏览报
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =50dip
            机器人:layout_alignParentTop =真
            机器人:layout_centerHorizo​​ntal =真
            广告:adSize =大旗
            广告:adUnitId =AD_UNIT_ID
            广告:loadAdOnCreate =真
            机器人:可聚焦=FALSE/>
    < / RelativeLayout的>
< /的FrameLayout>
 
android广告条植入 admob android植入广告 Android文档类资源 CSDN下载

I have a requirement to add or ignore the AdActivity of the Admob Ads. I am using a TabActivity and the activities navigated inside the tabs are maintained in an ArrayList. After integrating the ads when I navigate to the 3rd activity in a tab and then back press, instead of coming back to the previous activity (which happened before integrating the ads) I'm coming out of the app. While adding the activities to the ArrayList I'm setting the intent flag as FLAG_ACTIVITY_CLEAR_TOP. Could you please tell me how can I overcome coming out of the app on back press in the 3rd activity and instead be able to come to the 2nd activity and then to the 1st activity?

Thank you.

Edit:

04-10 13:19:32.519: E/AndroidRuntime(1392): FATAL EXCEPTION: main
04-10 13:19:32.519: E/AndroidRuntime(1392): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.admob/com.example.admob.activity.MainTabActivity}: java.lang.NullPointerException
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.os.Looper.loop(Looper.java:137)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread.main(ActivityThread.java:4424)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at java.lang.reflect.Method.invokeNative(Native Method)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at java.lang.reflect.Method.invoke(Method.java:511)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at dalvik.system.NativeStart.main(Native Method)
04-10 13:19:32.519: E/AndroidRuntime(1392): Caused by: java.lang.NullPointerException
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:101)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at com.google.ads.AdView.<init>(SourceFile:87)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at com.google.ads.doubleclick.DfpAdView.<init>(SourceFile:27)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at com.example.admob.activity.MainTabActivity.onCreate(MainTabActivity.java:80)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.Activity.performCreate(Activity.java:4465)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-10 13:19:32.519: E/AndroidRuntime(1392):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-10 13:19:32.519: E/AndroidRuntime(1392):     ... 11 more

解决方案

I finally found the solution for it! The problem was with the layout. I changed it accordingly and it worked. The following is my xml code:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dip" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <com.google.ads.doubleclick.DfpAdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="50dip"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            ads:adSize="BANNER"
            ads:adUnitId="AD_UNIT_ID"
            ads:loadAdOnCreate="true"
            android:focusable="false" />
    </RelativeLayout>
</FrameLayout>

 
精彩推荐
图片推荐