ProfileActivityFragment: Fix service connection tracking

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-08-07 18:42:38 -05:00
parent 372477d0e0
commit 00a755f46f

View File

@ -15,13 +15,27 @@ public class ProfileActivityFragment extends Fragment implements ServiceConnecti
public void onAttach(Context context) {
super.onAttach(context);
activity = (ProfileActivity) context;
activity.addServiceConnectionListener(this);
service = activity.getService();
}
@Override
public void onDetach() {
super.onDetach();
activity = null;
}
@Override
public void onStart() {
super.onStart();
activity.addServiceConnectionListener(this);
// If the service is already connected, there will be no callback, so run the handler now.
final ProfileServiceInterface service = activity.getService();
if (service != null)
onServiceConnected(service);
}
@Override
public void onStop() {
super.onStop();
activity.removeServiceConnectionListener(this);
}