From 91620845b99d7d6a0e119be688f1281f2b5b30ef Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Mon, 7 Aug 2017 18:42:38 -0500 Subject: ProfileActivityFragment: Fix service connection tracking --- .../com/wireguard/android/ProfileActivityFragment.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/com/wireguard/android/ProfileActivityFragment.java b/app/src/main/java/com/wireguard/android/ProfileActivityFragment.java index da394204..9ec9f51d 100644 --- a/app/src/main/java/com/wireguard/android/ProfileActivityFragment.java +++ b/app/src/main/java/com/wireguard/android/ProfileActivityFragment.java @@ -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); } -- cgit v1.2.3