字符串在AsyncTask中减少了

时间:2013-09-12 14:25:18

标签: java android string

我使用字符串来获取图像的base64字符串(我存储在values / strings.xml中)。但是当我尝试将该字符串的内容复制到另一个字符串时,原始字符串末尾的几个字符不会被复制到第二个字符串。原始字符串的长度为4072个字符。

class Task extends AsyncTask<String, Void, String> {

        private ProgressDialog dialog;
        private Context context;

        @SuppressWarnings("unused")
        private Activity activity;

        public Task(Activity activity) {
            this.activity = activity;
            context = activity;
            dialog = new ProgressDialog(context);
        }

        @Override
        protected void onPreExecute() {
            this.dialog.setMessage("Fetching data");
            this.dialog.show();
        }

        @Override
        protected String doInBackground(String... arg0) {
            // TODO Auto-generated method stub
            try {

                originalString = getResources().getString(R.string.s7);
                Log.i("orig", originalString);

                copiedString = originalString;
                Log.i("copy", copiedString);

            } catch (Exception e) {
                Log.i("excep", "hello");
            }

            return response;
        }

        @Override
        protected void onPostExecute(String result) {

            if (dialog.isShowing()) {
                dialog.dismiss();
            }

            if(result == null){
                 Log.d("TEMP_LOG","content is null");
                 return;
                }

        }

    }

这是两个字符串的日志结果。

09-12 19:44:16.382: I/orig(13150): /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/2wBDAQoLCw4NDhwQEBw7KCIoOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozv/wAARCADWAUADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjp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7V07gnp1pY4lQdOT1NXpbUyucU6OjYZSp9DTR0rsriyguUxLEG/Q1y+oWL2E5U5ZDyretZtdikynsy+7PHpS4xxSd+Kdg+tSXfQaVphAqY1GeSQB0oCxH1pjDFSlaaw

如您所见,第二个字符串最后缺少3个字符。怎么可能?

1 个答案:

答案 0 :(得分:1)

这些评论几乎都回答了这个问题,但这里是一个答案:

  1. 将实际字符串复制为:

    String copied = new String(original);
    

    或者:

    String copied = original.clone();
    

    虽然Java中的String对象是不可变的,但我认为这不是问题(参见#2)。

  2. 对原始文件执行String.length()检查并复制并记录该文件。问题实际上可能在记录器本身,因此无论源问题可能在其他地方。