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

Is it safe to (re-)use an (old) activity context? #768

Open
FrankEngler opened this issue Nov 12, 2024 · 0 comments
Open

Is it safe to (re-)use an (old) activity context? #768

FrankEngler opened this issue Nov 12, 2024 · 0 comments

Comments

@FrankEngler
Copy link

MainActivity gets an instance of GoogleMobileAdsConsentManager using its activity context via

googleMobileAdsConsentManager = GoogleMobileAdsConsentManager.getInstance(this)

GoogleMobileAdsConsentManager is a singleton:

companion object {
  @Volatile private var instance: GoogleMobileAdsConsentManager? = null

  fun getInstance(context: Context) =
    instance
      ?: synchronized(this) {
        instance ?: GoogleMobileAdsConsentManager(context).also { instance = it }
      }
}

If for any reason (e.g. configuration change) this or another activity try to get an instance of GoogleMobileAdsConsentManager they will ask for an instance with the actual context but will get an instance for the original activity context - of the now old and dead MainActivity. This might be the cause for #441. But even if it isn't this doesn't seem memory safe at all.

Can UserMessagingPlatform.getConsentInformation() work with an application context?
If so GoogleMobileAdsConsentManager.getInstance() should get an application context instead of an activity context.
If not GoogleMobileAdsConsentManager should not use singleton pattern.

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

1 participant