Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalStateException: destroy must be called on the main UI thread. #22

Closed
jenzz opened this issue Sep 13, 2016 · 1 comment

Comments

@jenzz
Copy link

jenzz commented Sep 13, 2016

I have spotted the following exception in our error logs:

09-13 16:15:08.719 18368-18377 E/System: java.lang.IllegalStateException: destroy must be called on the main UI thread.
                                                                at adn.b(:com.google.android.gms.DynamiteModulesA:251)
                                                                at com.google.android.gms.ads.internal.a.a(:com.google.android.gms.DynamiteModulesA:228)
                                                                at com.google.android.gms.ads.internal.client.ai.onTransact(:com.google.android.gms.DynamiteModulesA:59)
                                                                at android.os.Binder.transact(Binder.java:387)
                                                                at com.google.android.gms.ads.internal.client.zzu$zza$zza.destroy(Unknown Source)
                                                                at com.google.android.gms.ads.internal.client.zzae.destroy(Unknown Source)
                                                                at com.google.android.gms.ads.doubleclick.PublisherAdView.destroy(Unknown Source)
                                                                at com.appnexus.opensdk.mediatedviews.GooglePlayDFPBanner.destroy(GooglePlayDFPBanner.java:93)
                                                                at com.appnexus.opensdk.mediatedviews.DFPBanner.destroy(DFPBanner.java:54)
                                                                at com.appnexus.opensdk.MediatedAdViewController.finishController(MediatedAdViewController.java:191)
                                                                at com.appnexus.opensdk.MediatedAdViewController.cancel(MediatedAdViewController.java:540)
                                                                at com.appnexus.opensdk.AdViewRequestManager.cancel(AdViewRequestManager.java:42)
                                                                at com.appnexus.opensdk.AdFetcher.stop(AdFetcher.java:70)
                                                                at com.appnexus.opensdk.AdView.finalize(AdView.java:311)
                                                                at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:202)
                                                                at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:185)
                                                                at java.lang.Thread.run(Thread.java:818)

The problem seems to be that the AdView class overrides its finalize() method to stop the ad fetcher:

@Override
protected void finalize() {
  try {
    super.finalize();
  } catch (Throwable e) {}

  // Just in case, kill the adfetcher's service
  if (mAdFetcher != null)
    mAdFetcher.stop();
}

The JVM does not guarantee which thread will invoke finalize() (see java.lang.Daemons$FinalizerDaemon above)
so you would have to ensure you are on the main thread before stopping the ad fetcher.
Or, even better, move it to one of the other, custom lifecycle methods.

@josecu
Copy link

josecu commented Sep 13, 2016

Thanks, Jens! We'll get that patched up as soon as possible.

Best,
Jose

On Sep 13, 2016, at 11:32 AM, Jens Driller <notifications@github.commailto:notifications@github.com> wrote:

I have spotted the following exception in our error logs:

09-13 16:15:08.719 18368-18377 E/System: java.lang.IllegalStateException: destroy must be called on the main UI thread.
at adn.b(:com.google.android.gms.DynamiteModulesA:251)
at com.google.android.gms.ads.internal.a.a(:com.google.android.gms.DynamiteModulesA:228)
at com.google.android.gms.ads.internal.client.ai.onTransact(:com.google.android.gms.DynamiteModulesA:59)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.ads.internal.client.zzu$zza$zza.destroy(Unknown Source)
at com.google.android.gms.ads.internal.client.zzae.destroy(Unknown Source)
at com.google.android.gms.ads.doubleclick.PublisherAdView.destroy(Unknown Source)
at com.appnexus.opensdk.mediatedviews.GooglePlayDFPBanner.destroy(GooglePlayDFPBanner.java:93)
at com.appnexus.opensdk.mediatedviews.DFPBanner.destroy(DFPBanner.java:54)
at com.appnexus.opensdk.MediatedAdViewController.finishController(MediatedAdViewController.java:191)
at com.appnexus.opensdk.MediatedAdViewController.cancel(MediatedAdViewController.java:540)
at com.appnexus.opensdk.AdViewRequestManager.cancel(AdViewRequestManager.java:42)
at com.appnexus.opensdk.AdFetcher.stop(AdFetcher.java:70)
at com.appnexus.opensdk.AdView.finalize(AdView.java:311)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:202)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:185)
at java.lang.Thread.run(Thread.java:818)

The problem seems to be that the AdViewhttps://github.com/appnexus/mobile-sdk-android/blob/master/sdk/src/com/appnexus/opensdk/AdView.java#L304-L313 class overrides its finalize() method to stop the ad fetcher:

@OverRide
protected void finalize() {
try {
super.finalize();
} catch (Throwable e) {}

// Just in case, kill the adfetcher's service
if (mAdFetcher != null)
mAdFetcher.stop();
}

The JVM does not guarantee which thread will invoke finalize() (see java.lang.Daemons$FinalizerDaemon above)
so you would have to ensure you are on the main thread before stopping the ad fetcher.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://github.com//issues/22, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AGntO3FccKLY4FgYXo3d-_QftZnllDEgks5qpsIdgaJpZM4J70C4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants