Since I seem to have caught two activity references in a heapdump,
where the Activity is set to singleTask.
Romain's advice on avoiding memory leaks includes:
"Avoid non-static inner classes in an activity if you don't control
their life cycle, use a static inner class and make a weak reference
to the activity inside"
What does this mean exactly? I can't find any examples, positive, or
negative for this rule.
I do have some non static inner classes in my activity.
Most of them are anonymous inner classes like this one. I see hundreds
of them in the samples:
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
progressHorizontal.incrementSecondaryProgressBy(-1);
// Title progress is in range 0..10000
setSecondaryProgress(100 *
progressHorizontal.getSecondaryProgress());
}
});
Are anonymous inner classes okay?
I also see something like this in the samples:
private OnClickListener mStopRepeatingListener = new
OnClickListener() { . . .
Are member variables points to a non static anonymous inner class
okay? I might think so because a member variable's lifecycle is
controlled by the activity's lifecycle.
Or do I assume that all the API samples leak a lot of contexts?
Thanks for any insights
Nathan
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en