Android 从“活动”重新调整后,不调用setupWebView()的onResume()

Android 从“活动”重新调整后,不调用setupWebView()的onResume(),android,gps,webview,onresume,locationlistener,Android,Gps,Webview,Onresume,Locationlistener,我正在尝试在不刷新屏幕的情况下实现从活动返回。据我所知,有4种可能的状态需要处理: “使用无线网络”和“使用GPS卫星”都已禁用(用户将被定向到我的位置首选项,如果其中一个被禁用,则不允许继续) 其中一个已启用(2种可能性中的1种) 3,两者都已启用 我的问题是,从应用程序中的其他活动返回后,每次都会调用setupWebView(),导致屏幕刷新延迟 从首选项返回刷新是有必要的(例如,启用后GPS会得到修复),但在从活动返回后肯定不会,因为重新绘制屏幕的时间延迟会分散注意力并减慢我的应用程序的工

我正在尝试在不刷新屏幕的情况下实现从活动返回。据我所知,有4种可能的状态需要处理:

  • “使用无线网络”和“使用GPS卫星”都已禁用(用户将被定向到我的位置首选项,如果其中一个被禁用,则不允许继续)
  • 其中一个已启用(2种可能性中的1种) 3,两者都已启用
  • 我的问题是,从应用程序中的其他活动返回后,每次都会调用setupWebView(),导致屏幕刷新延迟

    从首选项返回刷新是有必要的(例如,启用后GPS会得到修复),但在从活动返回后肯定不会,因为重新绘制屏幕的时间延迟会分散注意力并减慢我的应用程序的工作流程

    请有人建议如何在我的onResume()中处理此问题,以避免所有setupWebview调用

    以下是我的主要活动中我的onResume()中的代码:

        @Override
    protected void onResume() {
        if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
                && !locationManager
                        .isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            createMyLocationDisabledAlert();
    
        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            locationManager.requestLocationUpdates(
                    LocationManager.GPS_PROVIDER, 500, 0, this);
            mostRecentLocation = locationManager
                    .getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (mostRecentLocation != null)
                setupWebView();
            else {
                mostRecentLocation = locationManager
                        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                setupWebView();
            }
        }
    
        else if (locationManager
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            locationManager.requestLocationUpdates(
                    LocationManager.NETWORK_PROVIDER, 500, 0, this);
            mostRecentLocation = locationManager
                    .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            if (mostRecentLocation != null)
                setupWebView();
            else {
                mostRecentLocation = locationManager
                        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                setupWebView();
            }
        }
    
        // locationManager.requestLocationUpdates(provider, 500, 0, this);
        // mostRecentLocation = locationManager.getLastKnownLocation(provider);
        // } else
        // mostRecentLocation = locationManager
        // .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        super.onResume();
    }
    

    使用
    boolean
    标志,并使用它跳过对
    setupWebView()
    的调用,以及
    onResume()
    方法中的大部分代码,以防您知道跳过它是安全的。您是调用
    startActivity()
    转到位置首选项屏幕的人,因此您知道是否需要调用
    setupWebView()