【问题标题】:Google Map blink in Android TV when open for long time长时间打开时,Google Map 在 Android TV 中闪烁
【发布时间】:2018-12-02 13:58:09
【问题描述】:

我有可以运行很长时间的 android TV 应用程序。我里面有谷歌地图,但 20-24 小时后谷歌地图开始闪烁。以下链接包含问题视频。

https://www.dropbox.com/s/vp8pbqc5z4zopbz/20180611_095004.mp4?dl=0

编辑

我无法共享整个源代码,但我使用了两个片段。一个片段包含地图,另一个包含图像的列表视图。我每 10 秒调用一次 web 服务,并更新 listview 图像和绑定地图,其中包含响应 web 服务的位置。

if ( map!=null) {
        if (activity.ambDetailList.size() > 0) {
            int i;
            double dist, currentLat = 0.0, currentLng = 0.0;
            ambOnlineList.clear();
            String ETA, SPEED;

            Marker marker;
            for (i = 0; i < activity.ambDetailList.size(); i++) {
                ambulanceDetail = activity.ambDetailList.get(i);
                dist = Math.sqrt(Math.pow(ambulanceDetail.getCurrentLat() - ambulanceDetail.getDestLat(), 2) + Math.pow(ambulanceDetail.getCurrentLng() - ambulanceDetail.getDestLng(), 2));
                double minute = ((dist * 100) / (ambulanceDetail.getSpeed() * 60 / 1000));
                double speed = ambulanceDetail.getSpeed() * 60 * 60 / 1000;
                Log.i("Minute", "----->>>>" + minute);
                if (speed >= 0.00 && speed <= 1.00) {
                    ETA = activity.getResources().getString(R.string.text_infinity);
                    SPEED = activity.getResources().getString(R.string.text_infinity);
                } else if (minute > 60) {
                    double hour = minute / 60;
                    int roundHour = (int) (minute / 60);
                    int min = (int) ((hour - roundHour) * 60);
                    ETA = roundHour + " hour " + min + " min";
                    SPEED = (int) (ambulanceDetail.getSpeed() * 60 * 60 / 1000) + " km/h ";
                } else {
                    ETA = (int) (minute) + " min ";
                    SPEED = (int) (ambulanceDetail.getSpeed() * 60 * 60 / 1000) + " km/h ";
                }

                ambulanceDetail.setEta(ETA);
                ambulanceDetail.setDisplayETA(ETA);
                ambulanceDetail.setDisplaySpeed(SPEED);

                if (markerList.get(ambulanceDetail.getAmbulanceId()) == null) {
                    MarkerOptions markerOptions = createMarker(ambulanceDetail);
                    marker = map.addMarker(markerOptions);
                    markerList.put(ambulanceDetail.getAmbulanceId(), marker);
                    markerArrayList.add(marker);
                    detailMap.put(marker, ambulanceDetail);
                } else {
                    marker = markerList.get(ambulanceDetail.getAmbulanceId());
                    if (marker.isVisible()) {
                        Location location = new Location("");
                        location.setLatitude(ambulanceDetail.getCurrentLat());
                        location.setLongitude(ambulanceDetail.getCurrentLng());
                        marker.setIcon(BitmapDescriptorFactory.fromBitmap(updateMarkerIcon(ambulanceDetail)));
                        marker.setPosition(new LatLng(ambulanceDetail.getCurrentLat(), ambulanceDetail.getCurrentLng()));
                    }
                }
                ArrayList<Integer> listId = new ArrayList<>();
                for (int m = 0; m < activity.ambDetailList.size(); m++) {
                    listId.add(activity.ambDetailList.get(m).getAmbulanceId());
                }
                for (int k = 0; k < markerArrayList.size(); k++) {
                    Marker m = markerArrayList.get(k);
                    if (!listId.contains(detailMap.get(m).getAmbulanceId())) {
                        markerArrayList.remove(m);
                        markerList.remove(detailMap.get(m).getAmbulanceId());
                        detailMap.remove(m);
                        m.remove();
                    }
                }
            }
            if (markerList.size() == 1 && activity.ambDetailList.size() == 1) {
                map.moveCamera(CameraUpdateFactory.newLatLngZoom(markerList.get(activity.ambDetailList.get(0).getAmbulanceId()).getPosition(), 16));
            } else {
                boundLatLang();
            }
            if (isFirstCall) {
                map.setBuildingsEnabled(true);
                isFirstCall = false;
            }
        } else {
            if (markerArrayList.size() > 0) {
                for (int i = 0; i < markerArrayList.size(); i++) {
                    Marker marker = markerArrayList.get(i);
                    marker.remove();
                }
                markerList.clear();
                markerArrayList.clear();
            }
            map.clear();
            if (detailMap.size() > 0)
                detailMap.clear();
        }
    }

【问题讨论】:

  • 没有源代码我很难帮你...
  • 请分享你的代码。
  • 我已经编辑了我的问题,并在每 10 秒调用一次 webservice 后放置了我正在做的事情的源代码。
  • 您是否填写了该服务中的recyclerview 数据?
  • @MayurPatel 是的

标签: android google-maps android-tv


【解决方案1】:

无论如何,您可以在地图开始闪烁之前重新启动应用程序(或者如果没有帮助 - 重新启动设备),例如在工作 15 小时后(或例如 500 次网络服务调用):

...
Intent restartIntent = getBaseContext().getPackageManager()
         .getLaunchIntentForPackage( getBaseContext().getPackageName() );
restartIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(restartIntent);
...

【讨论】:

  • 我无法重新启动设备或重新启动应用程序,因为这是一个医疗应用程序,它需要 24 x 7 开启。
  • @BhavyaGandhi 1)这只是解决方法而不是解决方案; 2)您的更新间隔为 10 秒 - 足以重新启动应用程序; 3) 您是否使用过Memory Profiler 或/和其他调试工具?
  • @BhavyaGandhi 4) 尝试每秒(或更频繁地)模拟 Web 服务调用,并在 1000 次调用后测试您的应用程序等...
  • 好的。让我试试
猜你喜欢
  • 1970-01-01
  • 2018-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多