0

I'm working on android to make an app that able to upload some photos to server. My problem here is when I want to completely remove an image from the list. I can remove the view from image view but when I upload the image. I got two image, one is the previous photo and another is the last photo I set on the image after remove. (Notes : image resources are from gallery). Below are my codes

Code to set a photo to image view

if(image.getDrawable() == null)
        {
            image.setImageBitmap(imageUpload);
            imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            image_data = baos.toByteArray();
            encoded_image_1 = Base64.encodeBytes(image_data);
        }
        else if(image2.getDrawable() == null)
        {
            image2.setImageBitmap(imageUpload);
            imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            image_data = baos.toByteArray();
            encoded_image_2 = Base64.encodeBytes(image_data);
        }
        else if(image3.getDrawable() == null)
        {
            image3.setImageBitmap(imageUpload);
            imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            image_data = baos.toByteArray();
            encoded_image_3 = Base64.encodeBytes(image_data);
        }

Code to remove image

else if(image3.getDrawable() != null)
            {
                image3.setImageBitmap(null);
                encoded_image_3 = null;
            }
            else if(image2.getDrawable() != null)
            {
                image2.setImageBitmap(null);
                encoded_image_2 = null;
            }
            else if(image.getDrawable() != null)
            {
                image.setImageBitmap(null);
                encoded_image_1 = null;
            }

Code to upload image

params_p.add(new BasicNameValuePair("image_1", encoded_image_1));
                params_p.add(new BasicNameValuePair("image_2", encoded_image_2));
                params_p.add(new BasicNameValuePair("image_3", encoded_image_3));

I appreciate any help from everyone, thanks.

3
  • use FileBody to send images to server, not Base64, this is much faster and more efficient Commented Aug 13, 2013 at 3:12
  • what do you mean by efficient? I'm talking about how to remove an image completely from view and assign a new one. Commented Aug 14, 2013 at 7:17
  • this is just an advice, actual answer I posted below Commented Aug 14, 2013 at 7:24

2 Answers 2

1

You should check if every encoded_image_* is null before adding it to parameters bundle. If the one wich should be null is not null - debug step by step removement process and find, why programm does not go into encoded_image_* = null section.

Sign up to request clarification or add additional context in comments.

7 Comments

When I try to debug step by step I found that it assigning to another image view, so it has 4 image when instead of 3. Do you have any idea to make it really null or something like that?
@RadityaKurnianto Can you post more code? In the question you said there are exactly 3 params_p.add, so it's unclear for me, how the forth may appear.
Actually there are 6 images, the images that send to the server are depend on how many image that assigned by user. This is my code pastebin.com/PqhGxRL2
@RadityaKurnianto Look - you set "image_data_*" to null, but then refer to encoded_image_*(it is unchanged) when sending images. In yout question there is no such mistake, but in the code you posted in the last comment - it is
Actually I've changed the code, when I write my code in this question, it's not work. Then I change to image_data_* and it still do the same.
|
0

You can try imageUpload.recycle()

1 Comment

Thanks, but it still do the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.