Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过迭代自定义位置对象的ArrayList创建GPX字符串_Java_Android_Android Asynctask_Iteration - Fatal编程技术网

Java 通过迭代自定义位置对象的ArrayList创建GPX字符串

Java 通过迭代自定义位置对象的ArrayList创建GPX字符串,java,android,android-asynctask,iteration,Java,Android,Android Asynctask,Iteration,问题 我目前正在通过迭代一个名为“CCTrackLocation”的自定义对象数组来创建一个gpx字符串。但是,这太慢了,尤其是在有许多位置的情况下。我还在异步任务中运行它 这是我的密码 for (CCTrackLocation location: trackLocations) { //Log.e("CCGPXUtils", "Time wasting"); String amendedString = gpxString + "<trkp

问题

我目前正在通过迭代一个名为“CCTrackLocation”的自定义对象数组来创建一个gpx字符串。但是,这太慢了,尤其是在有许多位置的情况下。我还在异步任务中运行它

这是我的密码

for (CCTrackLocation location: trackLocations) {
            //Log.e("CCGPXUtils", "Time wasting");
            String amendedString = gpxString + "<trkpt lat=\""+location.getLatitude()+"\" lon=\""+location.getLongitude()+"\">\n" +
                                                "<ele>"+location.getAltitude()+"</ele>\n" +
                                                "<time>"+CCDateUtility.convertTimestampIntoGPXFormat(location.getTimestamp())+"</time></trkpt>\n";
            gpxString = amendedString;
            amendedString = null;
for(CCTrackLocation:trackLocations){
//Log.e(“CCGPXUtils”,“浪费时间”);
字符串修正字符串=gpxString+“\n”+
“”+位置。getAltitude()+“\n”+
“+CCDateUtility.ConvertTimeStampIntoGPX格式(location.getTimestamp())+”\n”;
gpxString=修改后的字符串;
amendedString=null;
前500个左右的点被很好地转换,之后我在调试控制台中得到'GC\u FOR\u MALLOC'和'GC\u CONCURRENT'

问题

是否有一种更有效的方法来完成这项工作,而不会如此耗时


任何帮助都将不胜感激。

可能是我找到的最简单的解决方案

由于来自Objective-C背景,我不知道“StringBuilder”,但它们是我问题的解决方案

这是我的更新代码

StringBuilder stringBuilder = new StringBuilder(gpxString);
        for (CCTrackLocation location: trackLocations) {
            if (isCancelled())
                return null;
            //Log.e("CCGPXUtils", "Time wasting");
            stringBuilder.append("<trkpt lat=\""+location.getLatitude()+"\" lon=\""+location.getLongitude()+"\">\n" +
                                                "<ele>"+location.getAltitude()+"</ele>\n" +
                                                "<time>"+CCDateUtility.convertTimestampIntoGPXFormat(location.getTimestamp())+"</time></trkpt>\n");
}
return stringBuilder.toString();
StringBuilder-StringBuilder=新的StringBuilder(gpxString);
用于(CCTrackLocation位置:trackLocations){
如果(isCancelled())
返回null;
//Log.e(“CCGPXUtils”,“浪费时间”);
stringBuilder.append(“\n”+
“”+位置。getAltitude()+“\n”+
“+CCDateUtility.ConvertTimeStampIntoGPX格式(location.getTimestamp())+”\n“;
}
返回stringBuilder.toString();
结果

性能提高了100倍