我正在尝试从活动中实现返回,而无需刷新屏幕。据我所知,有四个可能的州可以处理:

  1. 两者都禁用“使用无线网络”和“使用GPS卫星”(用户被定向到我的位置首选项,并且在禁用两者的情况下不允许继续)
  2. 启用了这两个中的一个(2个可能性中的1个)3,两个都启用了

我的问题是,从我的应用程序中的其他活动返回后,每次引起屏幕刷新延迟时都会调用setupwebview()。

刷新是从偏好中返回的某种必要的返回(例如,启用后的GPS),但由于重新绘制屏幕的时间延迟会分散注意力并减慢我的应用程序的工作流程,因此肯定不会在活动中返回之后。

有人可以建议如何在我的OnResume()中处理此操作,以免避免所有设置呼叫。

这是我的主要活动中我的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().

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top