AdView导致应用程序变慢,可能的原因

8
我有一个包含WebView和ListView的屏幕,并且在屏幕底部有一个AdView。在老设备上(4.0-4.3 Android),WebView或ListView运行得很慢,直到AdView加载完成后才变得非常流畅。
Logcat显示AdMob尝试无数次但直到成功前都没有成功地加载某些内容。这可能是原因吗?如何解决?
10-10 01:02:20.954    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:20.964    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:20.974    7160-7214/com.test.test V/webcore﹕ webkitDraw start
10-10 01:02:20.974    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:21.004    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:21.004    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:21.004    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:21.004    7160-7214/com.test.test V/webcore﹕ webkitDraw start
10-10 01:02:21.014    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:21.024    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:21.024    7160-7214/com.test.test V/webcore﹕ webkitDraw start
10-10 01:02:21.044    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:21.044    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:21.054    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:21.054    7160-7214/com.test.test V/webcore﹕ webkitDraw start
10-10 01:02:21.054    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:21.054    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:21.074    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:21.074    7160-7214/com.test.test V/webcore﹕ webkitDraw start
10-10 01:02:21.084    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:21.084    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:21.094    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:21.104    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:21.114    7160-7214/com.test.test V/webcore﹕ webkitDraw start
10-10 01:02:21.114    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:21.124    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:21.134    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:21.134    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:21.144    7160-7214/com.test.test V/webcore﹕ webkitDraw start
10-10 01:02:21.144    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:21.164    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:21.164    7160-7214/com.test.test V/webcore﹕ webkitDraw start
10-10 01:02:21.164    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:21.174    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:21.184    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:21.184    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:21.184    7160-7214/com.test.test V/webcore﹕ webkitDraw start
10-10 01:02:21.194    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:21.194    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:21.194    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:21.204    7160-7214/com.test.test V/webcore﹕ webkitDraw start
10-10 01:02:21.224    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:21.234    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:21.234    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:22.754    7160-7163/com.test.test D/dalvikvm﹕ GC_CONCURRENT freed 380K, 12% free 7624K/8583K, paused 17ms+38ms, total 102ms
10-10 01:02:24.514    7160-7214/com.test.test V/webcore﹕ SET_BACKGROUND_COLOR arg1=0 arg2=0 obj=null
10-10 01:02:24.534    7160-7214/com.test.test V/webcore﹕ SET_ACTIVE arg1=0 arg2=0 obj=null
10-10 01:02:24.554    7160-7214/com.test.test V/webcore﹕ LOAD_DATA arg1=0 arg2=0 obj=android.webkit.WebViewCore$BaseUrlData@4163c488
10-10 01:02:24.564    7160-7160/com.test.test V/webview﹕ WEBCORE_INITIALIZED_MSG_ID
10-10 01:02:24.714    7160-7160/com.test.test V/webview﹕ setCertificate=null
10-10 01:02:24.744    7160-7160/com.test.test V/webview﹕ WEBCORE_NEED_TOUCH_EVENTS
10-10 01:02:24.894    7160-7160/com.test.test V/webview﹕ SELECTION_STRING_CHANGED
10-10 01:02:24.904    7160-7160/com.test.test V/webview﹕ SELECTION_STRING_CHANGED
10-10 01:02:24.904    7160-7160/com.test.test V/webview﹕ SELECTION_STRING_CHANGED
10-10 01:02:24.904    7160-7214/com.test.test V/webcore﹕ didFirstLayout standardLoad =true
10-10 01:02:24.904    7160-7214/com.test.test V/webcore﹕ Can't get the viewWidth yet
10-10 01:02:24.914    7160-7160/com.test.test V/webview﹕ SAVE_WEBARCHIVE_FINISHED
10-10 01:02:25.064    7160-7160/com.test.test I/Ads﹕ Scheduling ad refresh 60000 milliseconds from now.
10-10 01:02:25.084    7160-7214/com.test.test V/webcore﹕ LOAD_URL arg1=0 arg2=0 obj=android.webkit.WebViewCore$GetUrlData@41679bd8
10-10 01:02:25.084    7160-7214/com.test.test V/webcore﹕ CORE loadUrl about:blank
10-10 01:02:25.224    7160-7214/com.test.test V/webcore﹕ didFirstLayout standardLoad =true
10-10 01:02:25.234    7160-7214/com.test.test V/webcore﹕ setupViewport mRestoredScale=0.0 mViewScale=1.0 mTextWrapScale=1.0 data.mScale= 1.0
10-10 01:02:25.234    7160-7214/com.test.test V/webcore﹕ viewSizeChanged w=320; h=50; textwrapWidth=320; scale=1.0
10-10 01:02:25.244    7160-7214/com.test.test V/webcore﹕ WEBKIT_DRAW arg1=0 arg2=0 obj=null
10-10 01:02:25.254    7160-7214/com.test.test V/webcore﹕ webkitDraw start
10-10 01:02:25.254    7160-7214/com.test.test V/webcore﹕ webkitDraw NEW_PICTURE_MSG_ID
10-10 01:02:25.254    7160-7214/com.test.test V/webcore﹕ LOAD_URL arg1=0 arg2=0 obj=android.webkit.WebViewCore$GetUrlData@417630d8
10-10 01:02:25.264    7160-7214/com.test.test V/webcore﹕ CORE loadUrl javascript:AFMA_updateActiveView({"units":[{"viewBox":{"bottom":480,"right":320,"left":0,"top":0},"isScreenOn":true,"isPaused":false,"adFormat":"320x50_as","localVisibleBoxVisible":false,"activeViewJSON":{"click_string":"BBggidEcYVtTJNpG6pAPDj7qgBAD1k7K5qQIAABABOAHIAQPIA4gEoAYD","active_experiment_ids":"","is_active_view_immediate_enabled":true,"activeview_cpm_urls":[]},"hashCode":"a096ae7d-5728-4f8b-9c0b-95ea0edc1618","afmaVersion":"afma-sdk-a-v8115000.8115000.0","windowVisibility":0,"screenDensity":1,"localVisibleBox":{"bottom":0,"right":0,"left":0,"top":0},"isAttachedToWindow":true,"timestamp":13403686,"globalVisibleBox":{"bottom":0,"right":0,"left":0,"top":0},"isVisible":true,"adBox":{"bottom":430,"right":0,"left":0,"top":430},"hitBox":{"bottom":0,"right":0,"left":0,"top":0},"isMraid":false,"globalVisibleBoxVisible":false,"isStopped":false}]});
10-10 01:02:25.364    7160-7160/com.test.test I/Ads﹕ Ad finished loading.
10-10 01:02:25.594    7160-7160/com.test.test V/webview﹕ setCertificate=null
10-10 01:02:25.594    7160-7160/com.test.test V/webview﹕ WEBCORE_NEED_TOUCH_EVENTS
10-10 01:02:25.594    7160-7160/com.test.test V/webview﹕ SELECTION_STRING_CHANGED
10-10 01:02:25.594    7160-7160/com.test.test V/webview﹕ SELECTION_STRING_CHANGED
10-10 01:02:25.594    7160-7160/com.test.test V/webview﹕ SELECTION_STRING_CHANGED
10-10 01:02:25.604    7160-7160/com.test.test V/webview﹕ SAVE_WEBARCHIVE_FINISHED
10-10 01:02:25.604    7160-7160/com.test.test V/webview﹕ NEW_PICTURE_MSG_ID
10-10 01:02:25.644    7160-7160/com.test.test V/webview﹕ sendOurVisibleRect=(0,430,r=320,b=480
10-10 01:02:25.664    7160-7163/com.test.test D/dalvikvm﹕ GC_CONCURRENT freed 324K, 11% free 7716K/8583K, paused 24ms+32ms, total 130ms
10-10 01:02:26.434    7160-7214/com.test.test V/webcore﹕ LOAD_URL arg1=0 arg2=0 obj=android.webkit.WebViewCore$GetUrlData@416f4320
10-10 01:02:26.434    7160-7214/com.test.test V/webcore﹕ CORE loadUrl javascript:AFMA_updateActiveView({"units":[{"viewBox":{"bottom":480,"right":320,"left":0,"top":0},"isScreenOn":true,"isPaused":false,"adFormat":"320x50_as","localVisibleBoxVisible":false,"activeViewJSON":{"click_string":"BBggidEcYVtTJNpG6pAPDj7qgBAD1k7K5qQIAABABOAHIAQPIA4gEoAYD","active_experiment_ids":"","is_active_view_immediate_enabled":true,"activeview_cpm_urls":[]},"hashCode":"a096ae7d-5728-4f8b-9c0b-95ea0edc1618","afmaVersion":"afma-sdk-a-v8115000.8115000.0","windowVisibility":0,"screenDensity":1,"localVisibleBox":{"bottom":0,"right":0,"left":0,"top":0},"isAttachedToWindow":true,"timestamp":13403836,"globalVisibleBox":{"bottom":0,"right":0,"left":0,"top":0},"isVisible":true,"adBox":{"bottom":430,"right":0,"left":0,"top":430},"hitBox":{"bottom":0,"right":0,"left":0,"top":0},"isMraid":false,"globalVisibleBoxVisible":false,"isStopped":false}]});
10-10 01:02:26.474    7160-7214/com.test.test V/webcore﹕ LOAD_URL arg1=0 arg2=0 obj=android.webkit.WebViewCore$GetUrlData@416d1eb8
10-10 01:02:26.474    7160-7214/com.test.test V/webcore﹕ CORE loadUrl javascript:AFMA_updateActiveView({"units":[{"viewBox":{"bottom":480,"right":320,"left":0,"top":0},"isScreenOn":true,"isPaused":false,"adFormat":"320x50_as","localVisibleBoxVisible":true,"activeViewJSON":{"click_string":"BBggidEcYVtTJNpG6pAPDj7qgBAD1k7K5qQIAABABOAHIAQPIA4gEoAYD","active_experiment_ids":"","is_active_view_immediate_enabled":true,"activeview_cpm_urls":[]},"hashCode":"a096ae7d-5728-4f8b-9c0b-95ea0edc1618","afmaVersion":"afma-sdk-a-v8115000.8115000.0","windowVisibility":0,"screenDensity":1,"localVisibleBox":{"bottom":50,"right":320,"left":0,"top":0},"isAttachedToWindow":true,"timestamp":13404006,"globalVisibleBox":{"bottom":480,"right":320,"left":0,"top":430},"isVisible":true,"adBox":{"bottom":480,"right":320,"left":0,"top":430},"hitBox":{"bottom":50,"right":320,"left":0,"top":0},"isMraid":false,"globalVisibleBoxVisible":true,"isStopped":false}]});
10-10 01:02:26.484    7160-7214/com.test.test V/webcore﹕ SET_SCROLL_OFFSET arg1=1 arg2=0 obj=Point(0, 0)
10-10 01:02:26.514    7160-7214/com.test.test V/webcore﹕ SET_GLOBAL_BOUNDS arg1=0 arg2=0 obj=Rect(0, 430 - 320, 480)
10-10 01:02:26.524    7160-7214/com.test.test V/webcore﹕ VIEW_SIZE_CHANGED arg1=0 arg2=0 obj=android.webkit.WebViewClassic$ViewSizeData@416f7348
10-10 01:02:26.524    7160-7214/com.test.test V/webcore﹕ viewSizeChanged w=320; h=50; textwrapWidth=320; scale=1.0

编辑:

AdView在Activity.onCreate方法中创建。在启动时为VISIBLE。 http://pastebin.com/xZ7C8WGK


关于添加广告视图的代码以及何时添加它的代码将是很好的。 - Kamen Stoykov
做完了。如果有时间的话,看一下吧。 - ElSajko
我看了一下,一切看起来都很好。从你的日志文件中我看到网页视图正在“做”某些事情。也许问题出在布局上。你有硬件加速吗?显示应用程序视图是否需要重绘网页/列表视图?显示时是否有动画,并且是否有某些原因导致每帧都需要进行布局计算? - Kamen Stoykov
关键是没有Adview一切都可以顺利运作(或者在第一条广告加载后,需要大约1分钟的时间,这是不可接受的)。 - ElSajko
2个回答

3

我有一个简单的动画,当应用程序启动时会运行。在我加入 AdMob 广告之前,它运行得非常流畅。显然,AdMob 启动需要大量资源。

因此,我的解决方案是等待动画结束,然后开始加载广告。

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
     @Override
     public void run() {
          AdRequest bannerRequest = new AdRequest.Builder().build();
          mAdView.loadAd(bannerRequest);
     }
},2000);

Admob只有在启动时速度较慢,因此这解决了启动时的延迟。

2
很可能这是一个问题。如果我理解正确,可以通过删除AdView轻松检查它。我不知道你的应用程序的具体情况,但我建议你尝试使用Crosswalk Project
一般来说,与Admob的工作是同步的,但你可以尝试使用AsyncTask进行创建。或者,你可以尝试立即运行广告,但之后一段时间再运行。
另外,我建议尝试使用第三方插件来处理Admob。
最后,问题可能出在不稳定的互联网信道上。这就是我能想到的全部。希望一切顺利。

无法使用Crosswalk项目,因为它们不允许使用Service Context实例化视图(此外,它会使apk增加20mb)。创建AdView对象的AsyncTask,或将广告加载到adview的ASyncTask?我将查看第三方插件,不知道是否有替代admbo的选择,但仍然与admbo相关联。不稳定的互联网通道不是问题,因为许多用户都遇到了这个问题。 - ElSajko
尝试将所有内容都放在一个任务中。这只是一个想法。 所以我建议您查看第三方插件。祝你好运。很抱歉我无法提供帮助。 - user2413972

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接