AdView bug causing all webviews stop loading when orientation changes and multi-threads are running?

1,517 views
Skip to first unread message

Tony Cui

unread,
Nov 16, 2013, 8:30:39 PM11/16/13
to google-adm...@googlegroups.com
Dear all:

I just found a problem with Adview when screen orientation changes and multi-threads are running. I think this might be a bug of Adview. And this problem impacts all the webviews in the application. The webviews stop loading any content, i.e. they either show blank or the content that was shown before.

The test environment is 
Platform: Google Nexus S + Android 4.1.2 (not only this platform, a lot of other platforms, even the emulators are affected)
Ads SDK: 6.4.1 (we also tested Ads SDK 4.1.1 which has the same problem)

The way to reproduce this issue is
1. download the attached .7z file, unzip it and get the HelloAndroid project;
2. run the HelloAndroid project in the above platform, or other platforms even emulators which may also be affected;
3. After the app starts, it shows "OnCreate function called." in the webview, and also the time when the content is loaded. Meanwhile, ads lso show on the top of the screen;
4. Now click the "Start Calculating Thread" button, at the same time, rotate screen to change its orientation, then immediately change orientation again, etc... meanwhile, continously click the "Start Calculating Thread" button immediately after last calculating task finishes. Repeat these actions for a few times, then you will notice that the webview does not reload. Its text is always "Background calculating thread done" whether you rotate screen or not. (Its text could also be "Configuration changed" whether you click the "Start Calculating Thread" button or not). The time shown in the webview is not updated either. The ads are not shown.

From the log file (the log file is also included in the 7z attachement), we can see a lot of ads errors like:

11-17 11:51:11.254: I/Ads(7411): AdLoader timed out after 60000ms while getting the URL.
11-17 11:51:11.254: I/Ads(7411): onFailedToReceiveAd(A network error occurred.)

We also get an exception, but this exception appears after the above error came out.

11-17 11:53:14.597: W/Ads(7411): An error occurred while loading data in AdWebView:
11-17 11:53:14.609: I/Ads(7411): The following was caught and handled:
11-17 11:53:14.609: I/Ads(7411): java.lang.NullPointerException
11-17 11:53:14.609: I/Ads(7411): at android.webkit.WebViewClassic.loadDataWithBaseURL(WebViewClassic.java:2564)
11-17 11:53:14.609: I/Ads(7411): at android.webkit.WebView.loadDataWithBaseURL(WebView.java:842)
11-17 11:53:14.609: I/Ads(7411): at com.google.ads.internal.AdWebView.loadDataWithBaseURL(SourceFile:229)
11-17 11:53:14.609: I/Ads(7411): at com.google.ads.internal.c$c.run(SourceFile:164)
11-17 11:53:14.609: I/Ads(7411): at android.os.Handler.handleCallback(Handler.java:615)
11-17 11:53:14.609: I/Ads(7411): at android.os.Handler.dispatchMessage(Handler.java:92)
11-17 11:53:14.609: I/Ads(7411): at android.os.Looper.loop(Looper.java:137)
11-17 11:53:14.609: I/Ads(7411): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-17 11:53:14.609: I/Ads(7411): at java.lang.reflect.Method.invokeNative(Native Method)
11-17 11:53:14.609: I/Ads(7411): at java.lang.reflect.Method.invoke(Method.java:511)
11-17 11:53:14.609: I/Ads(7411): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-17 11:53:14.609: I/Ads(7411): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-17 11:53:14.609: I/Ads(7411): at dalvik.system.NativeStart.main(Native Method)

We believe this issue is caused by AdView not by webView or the thread programming based on the following observations:
1. We have found that, even if we place the webView in another activity, i.e. the multithread activity only includes a button and adView, this problem still comes out after the above reproducing steps. And after the problem comes we move the other activity which includes the webView, it still stops loading anything. In other words, it is not the webView who triggers the problem.
2. The calculating thread is very simple, no UI operation is included in it. Start and stop loading ads are always done in the main thread.

The codes are quite simple. The manifest file is:

<?xml version="1.0" encoding="utf-8"?>
      package="com.example.helloandroid"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />
<!--  uses-permission android:name="android.permission.INTERNET"/-->
    
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloAndroid"
                  android:label="@string/app_name"
                  android:configChanges="orientation|keyboardHidden|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
<activity android:name="com.google.ads.AdActivity"
              android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>
</manifest>

The only layout file is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<LinearLayout 
   android:orientation="vertical"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_alignParentTop="true"
   android:id="@+id/adsHolder" >
</LinearLayout>

    <android.webkit.WebView
android:id="@+id/webview_show_something"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/button1"
android:layout_below="@+id/adsHolder"
></android.webkit.WebView>
    
<Button
   android:id="@+id/button1"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_alignParentBottom="true"
   android:text="Start Calculating Thread" />

</RelativeLayout>

And the HelloAndroid.java file is:

package com.example.helloandroid;

import java.text.DateFormat;
import java.util.Date;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class HelloAndroid extends Activity {
    // Need handler for callbacks to the UI thread
    public Handler mHandler;
    
    public WebView mwebView;

    public AdView madView;
    
    public Thread mthread = null;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mHandler = new Handler(); // handler is attached to the UI thread.
        
        Button btn = (Button) findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
final ProgressDialog dlgProgress = ProgressDialog.show(HelloAndroid.this, "Please wait",
"Background calculating ...", true);
mthread = new Thread(new Runnable(){

@Override
public void run() {
for (int idx = 0; idx < 10000; idx ++) {
for (int idx1 = 0; idx1 < 10; idx1 ++) {
int a = idx + idx1;
a ++;
}
}
mHandler.post(new Runnable() {

@Override
public void run() {
dlgProgress.dismiss();
if (madView != null) {
    madView.loadAd(new AdRequest());
}
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
mwebView.loadDataWithBaseURL("http://",
               "<html><body><h1>Background calculating thread done.</h1><p>" + currentDateTimeString + "</p></body></html>",
               "text/html","utf-8","");
mthread = null;
}
});
}
});
if (madView != null) {
    madView.stopLoading();
}
mthread.start();
}
       
        });
        
        mwebView = (WebView)findViewById(R.id.webview_show_something);
mwebView.setVerticalScrollBarEnabled(true);
mwebView.setHorizontalScrollBarEnabled(true);
mwebView.getSettings().setBuiltInZoomControls(true);
mwebView.setWebViewClient(new WebViewClient());
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
mwebView.loadDataWithBaseURL("http://",
                "<html><body><h1>OnCreate function called.</h1><p>" + currentDateTimeString + "</p></body></html>",
                "text/html","utf-8","");
startLoadingAds();
        
    }
    
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// because it is smart_banner, adview has to be dynamically generated to fit landscape or portrait screen.
stopLoadingAds();
if (mthread == null) { // only if calculating thread finishes we start to load ads.
startLoadingAds();
}
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
mwebView.loadDataWithBaseURL("http://",
                "<html><body><h1>Configuration changed.</h1><p>" + currentDateTimeString + "</p></body></html>",
                "text/html","utf-8","");
  }
public void stopLoadingAds() {
// reset the adView.
    if (madView != null) {
    madView.stopLoading();
    ViewGroup viewGroup = (ViewGroup) madView.getParent();
if (viewGroup != null)
{
viewGroup.removeView(madView);
}
madView.removeAllViews();
    madView.destroy(); // not required.
    madView = null;
      }
}
public void startLoadingAds() {
LinearLayout layoutAdView = (LinearLayout)findViewById(R.id.adsHolder);
layoutAdView.removeAllViews();
madView = new AdView(this, AdSize.SMART_BANNER, "ca-app-pub-9004844319824679/3238161316");
if (madView != null) {
layoutAdView.addView(madView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        madView.loadAd(new AdRequest());
}
}
}

AdView_issue.7z

Amy Quispe (AdMob SDK Team)

unread,
Nov 19, 2013, 7:40:23 PM11/19/13
to google-adm...@googlegroups.com
Hi Tony,

We reproduced the issue with AdMob 6.4.1, but it looks like it's been fixed in Google Play Services, so hopefully you can upgrade ASAP. ^_^

Amy

Tony Cui

unread,
Nov 19, 2013, 8:13:41 PM11/19/13
to google-adm...@googlegroups.com
Hi Amy:

Thanks for your response. My test phones have google play services version 4.0.33 (910055-34). I think this is the latest version, right? But I still have the same issue.

And most important, I am an app developer, I can upgrade my google play services but I cannot guarantee my users update google play services. If they use an old version of google play services, they will have very bad experience with my app. As such, I hope you could provide a solution which can be controlled by developer. I mean hopefully you could fix this issue in Admob SDK lib instead of a third party application. I will appreciate your help very much if you could do this.

Regards
Tony

Amy Quispe (AdMob SDK Team)

unread,
Nov 19, 2013, 8:23:12 PM11/19/13
to google-adm...@googlegroups.com
Hi Tony,

The Mobile Ads SDK is part of Play Services now. You can read the announcement here. This is the version we plan to iterate on in the future. You should use this instead of AdMob 6.4.1. You can include the most recent Play Services library when you distribute your app.

Hope this clears things up!

Amy

Ramesh Dhananjeyan

unread,
Dec 30, 2013, 4:19:37 AM12/30/13
to google-adm...@googlegroups.com
Hi Amy,

  I setup using Play Services. But now i am getting error like this "The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.". I am getting ads, it loads first time, then blank Banner appearing.. I just switched from SDK to Playservices. Could you please Help me as soon as possible.

Ramesh.

Amy Quispe (AdMob SDK Team)

unread,
Jan 3, 2014, 5:24:52 PM1/3/14
to google-adm...@googlegroups.com
Hi Ramesh,

Make sure that it's included as a library project. Some helpful instructions here.

Amy Quispe

William Bagayoko

unread,
Jan 10, 2014, 5:48:38 PM1/10/14
to google-adm...@googlegroups.com
Hi Amy,

I'm pretty sure I have Android apps that are experiencing this problem as well.

We are also using DFP, and as such can't update to the google play services library at this time.

Are there any stopgap measures for DoubleClick for Publishers Users? 

Is it possible there is a past version which doesn't have this issue?

Would you know of a timetable for DFP inclusion in the Play Services Library?

Thank you for your time
William

Amy Quispe (AdMob SDK Team)

unread,
Jan 16, 2014, 1:38:06 PM1/16/14
to google-adm...@googlegroups.com
HI William,

The latest version of Play Services (now out) supports DFP. You should be able to safely upgrade.

Amy Quispe

William Bagayoko

unread,
Jan 17, 2014, 8:36:56 PM1/17/14
to google-adm...@googlegroups.com
I have upgraded, but now I'm getting ANRs after multiple screen rotation.

main thread at the time of an ANR:

  at aal.b(SourceFile:287)
  at abm.f(SourceFile:33)
  at xq.r(SourceFile:593)
  at xq.b(SourceFile:168)
  at ya.onTransact(SourceFile:59)
  at android.os.Binder.transact(Binder.java:347)
  at com.google.android.gms.internal.ac$a$a.destroy(Unknown Source)
  at com.google.android.gms.internal.ag.destroy(Unknown Source)
  at com.google.android.gms.ads.doubleclick.PublisherAdView.destroy(Unknown Source)
  at ...Fragment.onDestroy(..Fragment.java:170)
  at android.support.v4.app.Fragment.performDestroy(Fragment.java:1720)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1056)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
  at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:1921)
  at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:335)
  at com.actionbarsherlock.app.SherlockFragmentActivity.onDestroy(SherlockFragmentActivity.java:87)
  at ..Activity.onDestroy(..Activity.java:104)
  at android.app.Activity.performDestroy(Activity.java:5302)
  at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
  at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3486)
  at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3517)
  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3717)
  at android.app.ActivityThread.access$700(ActivityThread.java:141)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:137)
  at android.app.ActivityThread.main(ActivityThread.java:5103)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:525)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  at dalvik.system.NativeStart.main(Native Method)

I'm destroying the ad as noted from the documentation. Is this necessary?

Are these types of issues known?
 
Thank you all for the update. 

William

jona...@lentor.io

unread,
Jan 24, 2014, 5:19:53 AM1/24/14
to google-adm...@googlegroups.com
I am also facing an issue with PublisherAdView, which somehow leaks on back press (onDestroy), causing an ANR.

I did call resume(), pause(), and destroy() as demonstrated here (in the same order as shown): http://developer.android.com/reference/com/google/android/gms/ads/doubleclick/PublisherAdView.html

01-24 00:16:26.745    1458-1458/com.inmobi.tmi.ui E/ActivityThread﹕ Activity com.inmobi.tmi.ui.MainActivity has leaked ServiceConnection asj@416f7e18 that was originally bound here
    android.app.ServiceConnectionLeaked: Activity com.inmobi.tmi.ui.MainActivity has leaked ServiceConnection asj@416f7e18 that was originally bound here
            at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
            at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
            at android.app.ContextImpl.bindService(ContextImpl.java:1418)
            at android.app.ContextImpl.bindService(ContextImpl.java:1407)
            at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
            at xh.b(SourceFile:92)
            at xh.a(SourceFile:121)
            at rz.d(SourceFile:88)
            at rz.b(SourceFile:129)
            at rw.a(SourceFile:239)
            at rw.a(SourceFile:176)
            at aal.a(SourceFile:116)
            at abn.run(SourceFile:14)
            at abp.run(SourceFile:30)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
            at java.lang.Thread.run(Thread.java:856)
01-24 00:16:26.745    1458-1478/com.inmobi.tmi.ui E/AndroidRuntime﹕ FATAL EXCEPTION: AdWorker #1
    java.lang.IllegalArgumentException: Service not registered: asj@416f7e18
            at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:921)
            at android.app.ContextImpl.unbindService(ContextImpl.java:1451)
            at android.content.ContextWrapper.unbindService(ContextWrapper.java:484)
            at xh.a(SourceFile:135)
            at rz.d(SourceFile:88)
            at rz.b(SourceFile:129)
            at rw.a(SourceFile:239)
            at rw.a(SourceFile:176)
            at aal.a(SourceFile:116)
            at abn.run(SourceFile:14)
            at abp.run(SourceFile:30)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
            at java.lang.Thread.run(Thread.java:856)

Anthony Ruth

unread,
Mar 9, 2014, 5:37:29 PM3/9/14
to google-adm...@googlegroups.com
I am facing the same problem. Google play services crashes my app after screen is rotated. Updated to latest version of google play services in ADT(Rev 15) and brought in the latest version of the library project, but no change. 

03-09 17:33:13.139: E/GooglePlayServicesUtil(10340): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
03-09 17:33:13.169: E/AndroidRuntime(10340): FATAL EXCEPTION: AdWorker #3
03-09 17:33:13.169: E/AndroidRuntime(10340): java.lang.IllegalArgumentException: Service not registered: azc@41549ff0
03-09 17:33:13.169: E/AndroidRuntime(10340): at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1022)
03-09 17:33:13.169: E/AndroidRuntime(10340): at android.app.ContextImpl.unbindService(ContextImpl.java:1740)
03-09 17:33:13.169: E/AndroidRuntime(10340): at android.content.ContextWrapper.unbindService(ContextWrapper.java:484)
03-09 17:33:13.169: E/AndroidRuntime(10340): at wr.a(SourceFile:135)
03-09 17:33:13.169: E/AndroidRuntime(10340): at tt.d(SourceFile:88)
03-09 17:33:13.169: E/AndroidRuntime(10340): at tt.b(SourceFile:129)
03-09 17:33:13.169: E/AndroidRuntime(10340): at tq.a(SourceFile:239)
03-09 17:33:13.169: E/AndroidRuntime(10340): at tq.a(SourceFile:176)
03-09 17:33:13.169: E/AndroidRuntime(10340): at zv.a(SourceFile:117)
03-09 17:33:13.169: E/AndroidRuntime(10340): at aay.run(SourceFile:14)
03-09 17:33:13.169: E/AndroidRuntime(10340): at aba.run(SourceFile:30)
03-09 17:33:13.169: E/AndroidRuntime(10340): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
03-09 17:33:13.169: E/AndroidRuntime(10340): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
03-09 17:33:13.169: E/AndroidRuntime(10340): at java.lang.Thread.run(Thread.java:864)

Amy Quispe (AdMob SDK Team)

unread,
Mar 10, 2014, 8:56:55 PM3/10/14
to google-adm...@googlegroups.com
Hi everyone,

We're rolling out a fix sometime next week. Hopefully you'll see fewer crashes.

Amy Quispe

E Tijori

unread,
Mar 10, 2014, 9:28:11 PM3/10/14
to google-adm...@googlegroups.com
Hi can you tell me what is the limit of clicks on a ad from one device in a day

Sent from my iPhone
--

---
You received this message because you are subscribed to the Google Groups "Google AdMob Ads Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
com.
For more options, visit https://groups.google.com/d/optout.
>

Amy Quispe (AdMob SDK Team)

unread,
Mar 11, 2014, 2:00:09 PM3/11/14
to google-adm...@googlegroups.com
This sounds like you want to click your own ads (or ask others to click on ads for you). Don't do that. You will get banned.

Amy Quispe
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.

Alejandro Javier Medero

unread,
Nov 17, 2015, 2:37:47 PM11/17/15
to Google Mobile Ads SDK Developers
Hi, is this issue fixed?? I'm facing it when using a webview to load a local html file, and a Banner Ad below it.

After loading some ads, the webview and the adview stops working (both of them get blank page). 

I'm using play services 8.3.0.

Vu Chau (MobileAds SDK Team)

unread,
Nov 17, 2015, 5:08:21 PM11/17/15
to Google Mobile Ads SDK Developers
Hi Alejandro,

Are you able to reproduce the issue in our sample app?  Can you send across a zipped code project that demonstrates this issue?

Thanks,

Vu Chau
Mobile Ads SDK Team
Reply all
Reply to author
Forward
0 new messages