blob: aa75db70e18ee828f0bc1f33217f1523c46b1220 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package cgeo.geocaching.ui;
import android.app.Activity;
import android.os.Handler;
import java.lang.ref.WeakReference;
/**
* Standard handler implementation which uses a weak reference to its activity. This avoids that activities stay in
* memory due to references from the handler to the activity (see Android Lint warning "HandlerLeak")
*
* Create static private subclasses of this handler class in your activity.
*
*/
public abstract class WeakReferenceHandler<ActivityType extends Activity> extends Handler {
private final WeakReference<ActivityType> activityRef;
protected WeakReferenceHandler(final ActivityType activity) {
this.activityRef = new WeakReference<>(activity);
}
protected ActivityType getActivity() {
return activityRef.get();
}
}
|