diff --git a/src/com/android/settings/vpn2/VpnSettings.java b/src/com/android/settings/vpn2/VpnSettings.java index 4e21c05da77..e5a78b68f7e 100644 --- a/src/com/android/settings/vpn2/VpnSettings.java +++ b/src/com/android/settings/vpn2/VpnSettings.java @@ -222,6 +222,7 @@ public class VpnSettings extends RestrictedSettingsFragment implements public boolean handleMessage(Message message) { mUpdater.removeMessages(RESCAN_MESSAGE); + // Run heavy RPCs before switching to UI thread final List vpnProfiles = loadVpnProfiles(mKeyStore); final List vpnApps = getVpnApps(getActivity(), /* includeProfiles */ true); @@ -230,10 +231,15 @@ public class VpnSettings extends RestrictedSettingsFragment implements final Set readOnlyUsers = getReadOnlyUserProfiles(); - // Refresh the PreferenceGroup which lists VPNs + // Refresh list of VPNs getActivity().runOnUiThread(new Runnable() { @Override public void run() { + // Can't do anything useful if the context has gone away + if (!isAdded()) { + return; + } + // Find new VPNs by subtracting existing ones from the full set final Set updates = new ArraySet<>();