wireguard-android/app/src/main/java/com/wireguard/android/ProfileActivityFragment.java
Samuel Holland 00a755f46f ProfileActivityFragment: Fix service connection tracking
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2017-08-07 18:42:38 -05:00

52 lines
1.3 KiB
Java

package com.wireguard.android;
import android.app.Fragment;
import android.content.Context;
/**
* Base class for fragments that are part of a ProfileActivity.
*/
public class ProfileActivityFragment extends Fragment implements ServiceConnectionListener {
private ProfileActivity activity;
protected ProfileServiceInterface service;
@Override
public void onAttach(Context context) {
super.onAttach(context);
activity = (ProfileActivity) context;
}
@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);
}
@Override
public void onServiceConnected(ProfileServiceInterface service) {
this.service = service;
}
@Override
public void onServiceDisconnected() {
service = null;
}
}