Then call adView.destroy() and set adView = null in the activity's
onDestroy(). Again, use try/catch... just in case. You do not need to
do any error processing, but you don't want the app to crash just
because the AdView has a cleanup problem.
Although the SDK should probably handle this (and a few other things),
since it's your app, doing the cleanup is a good idea regardless of
who "should" do it.
Also, unless you leak the adView to your service, it should not end up
anywhere outside of your activity/activities. Since your service
should not load an XML file or inflate views (there is no UI), that
should not be a problem. It should be easy to check (in most cases,
service level communication is through Intents, but using
startService() with a service object that, for some reason, has your
activity (or specifically the AdView) would cause a leak - most
likely, though, you would see a different error because it would try
to modify the UI from a non-UI thread).
4.1.0 works pretty well. We're still trying to get comfortable with
4.1.1 (which, like most code, fixes some issues but introduces new
ones, as discussed in other threads).
Good luck!
-Jim
I've just added the stopLoading() before the destroy(), so that should
remove the NullPointerException I received a few times.
As I'm about to release an update with this fix, may I ask you one more
question before I do:
The only thing I pass to my service is the context, which can be an activity
(as it is a context in the first place). Didn't used to have any issues, but
here is how it is used:
static public void StartService(Context context)
{
if (service_intent == null)
service_intent = new Intent(context, bmw_service.class);
context.startService(service_intent);
}
Tried service_intent = new Intent(); but then the service does not start.
Could this be causing AdMob to continue running in the background?
With the newly added stopLoading(), that should prevent any further problems
and CPU consumption, right?
Thanks for your support, much appreciated!
Cedric.
-----Message d'origine-----
De : google-adm...@googlegroups.com
[mailto:google-adm...@googlegroups.com] De la part de SPA Support
Envoyé : vendredi 5 août 2011 19:34
À : google-adm...@googlegroups.com
Objet : Re: Help needed:AdMob continues to run after app screen is
destroyed!?
Good luck!
-Jim
-----
Aucun virus trouvé dans ce message.
Analyse effectuée par AVG - www.avg.fr
Version: 10.0.1391 / Base de données virale: 1518/3812 - Date: 05/08/2011
Passing the activity context will not leak the AdView. We do that in
some places and don't have a problem.
-Jim
I do all the clean-up in onPause, and recreate each time, less nice but when
I was doing the clean-up in onStop() I could see the SDK continuing to run
(hitting home or not) when switching between multiple screens. As if the
onResume() was creating a new view without the previous one being cleaned
during onPause().
I haven't been able to reproduce the CPU/battery issue within the emulator
or my devices for a while, though I just received reports of the issue
occurring again.
Hopefully the stopLoading() will fix it for good!
Thanks for your time,
Cedric.
-----Message d'origine-----
De : google-adm...@googlegroups.com
[mailto:google-adm...@googlegroups.com] De la part de SPA Support
Envoyé : vendredi 5 août 2011 20:53
The crash report is below. Here is the code I use to do the manual clean-up
during onPause() of any of my activities, following your previous
suggestions:
public static void detachAdView(Activity parent)
{
AdView av = (AdView)parent.findViewById(R.id.adView);
if (av != null)
{
ViewGroup parentView = (ViewGroup)av.getParent();
try
{
av.stopLoading();
}
catch(Exception e)
{
}
parentView.removeView(av);
try
{
av.destroy();
}
catch(Exception e)
{
}
}
}
Here is the crash report:
java.lang.NullPointerException
at android.webkit.WebView.stopLoading(WebView.java:2026)
at c$a.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4196)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:8
39)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Thanks for any advice you may provide, as this is becoming an issue, users
complaining about the stability of the app!
Regards,
Cedric.
When you mention the 'Adsense reporting bug', is it affecting this 4.1.1
release? I seem to have lost Adsense revenue since the 14/08.
Anyway, shit happens I'm the first to know that...
[ Unfortunately the Android one-way comment system is not helping dev, but
frustrated users release their anger. I'm not sure a 2-way communication
will help but increase the angry exchanges between users-devs. A
limited-1-time-2-way communication might help though. ]
Thanks again for patiently explaining the situation.
It looks like they missed an explicit call to unregister the receiver
during stopLoading or onDestroy. Is that what you are saying is the
bug? I would think that Android GC would stop leaks, so it's really a
hit miss type situation, right?
Try adding this to your code above, after av.destroy()
av = null;
Also, make sure you do that to all references to the AdView you might
have elsewhere in the Activity. I have seen an explicit null reduce GC
time, if that is the problem here.
-Jim
--
Thanks,
SPA Support