I've started tracking memory leaks on my Android app and, thanks to the great LeakCanary library, I found that some of my activities that include a GooglePlusButton are leaking a context.
Unfortunately I didn't find a workaround to avoid it. As described on this old bug report, the initialize method hides the fact that its needs a context. Furthermore, it needs an Activity context; the Android studio decompiler shows it (the bug reporter tell it as well):
public void initialize(String var1, int var2) {
zzab.zza(this.getContext() instanceof Activity, "To use this method, the PlusOneButton must be placed in an Activity. Use initialize(String, OnPlusOneClickListener).");
Is there any workaround better than completely get rid of the +1 button?
Note: I'm using Google Play Services 9.6.0 but this problem also occurred on previous versions.
As it is said in the error message if you are using G+1 button not in an activity (for example in the app bar menu) you need to initialise it by calling method initialize(String, OnPlusOneClickListener).
More info here: https://developers.google.com/android/reference/com/google/android/gms/plus/PlusOneButton