Fix force close for updating UI after activity destroyed.

If activity is finishing or destroyed, getting activity context will return null results in settings app force close.

Do not call scan callback if network select activity is finishing or destroyed.

Test: build pass and run NetworkSelectSettingsTest unit test pass.

Bug: 372123288
Change-Id: I28307490c75fe04d54dcf1637f33f4b9ba1fe635
This commit is contained in:
hoffc
2024-10-22 09:27:35 +08:00
committed by Hoff Cheng
parent 0583090e98
commit a9002d157c

View File

@@ -219,7 +219,7 @@ public class NetworkSelectSettings extends DashboardFragment {
setProgressBarVisible(true);
mNetworkScanJob = mNetworkScanRepository.launchNetworkScan(getViewLifecycleOwner(),
(networkScanResult) -> {
if (isPreferenceScreenEnabled()) {
if (isPreferenceScreenEnabled() && !isFinishingOrDestroyed()) {
scanResultHandler(networkScanResult);
}