0

I hope u all are fine I am facing a problem in my app. In my app i am having functionality where user needs to upload image and signature in database.Now i am facing problem when user click on click image button user is navigated to gallery at that time android shows app crash pop-up and getting exception TransactionTooLarge in logcat. When i tried to remove upload image functionality and only upload signature i see that my app doesn't crash.so i came to conclusion that my crash when i provide upload image functionality.

Can anybody tell me how to solve this exception as i have gone through stack overflow but i didn't found any solution to solve my problem.

Below is the Exceptiom:

Caused by: android.os.TransactionTooLargeException: data parcel size 1394920 bytes
    at android.os.BinderProxy.transactNative(Native Method)
    at android.os.BinderProxy.transact(Binder.java:615)
    at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3636)
    at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3773)
    at android.os.Handler.handleCallback(Handler.java:751) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:154) 
    at android.app.ActivityThread.main(ActivityThread.java:6119) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

Below is the code:

    public class Verifydocument extends Fragment implements View.OnClickListener {
    private Toolbar toolbar;
    private String booking_id;
    private SignaturePad signaturePad;
    private Button CheckIn;
    private FirebaseStorage mstorageRef;
    private FirebaseAuth firebaseAuth;
    private Button Clear, ClickImage, UploadImage;
    private Uri mainuri = null;
    private ImageView Userimage;
    private FirebaseFirestore firebaseFirestore;
    private CollectionReference collectionReference;
    private String RoomType;
    private Long No_of_guest;
    private List<RoomAvaibilityViewModel> roomAvaibilityViewModels;

    public void Verifydocument() {
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);


    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_verifydocument, container, false);

        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable final Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        booking_id = VerifydocumentArgs.fromBundle(getArguments()).getBookingId();
        RoomType = VerifydocumentArgs.fromBundle(getArguments()).getRoomType();
        No_of_guest = VerifydocumentArgs.fromBundle(getArguments()).getNoOfGuest();
//        Signature Pad
        signaturePad = view.findViewById(R.id.signaturePad2);
//        Check-in,Clear,UploadImage,ClickImage
        CheckIn = view.findViewById(R.id.Check_in);
        ClickImage = view.findViewById(R.id.Click_btn);
        UploadImage = view.findViewById(R.id.Upload_Btn);
        Clear = view.findViewById(R.id.Clear_Sign);
//        Firebase
        mstorageRef = FirebaseStorage.getInstance();
        firebaseAuth = FirebaseAuth.getInstance();
        firebaseFirestore = FirebaseFirestore.getInstance();
        collectionReference = firebaseFirestore.collection("Room Availability").document().getParent();
//        UserImage
        Userimage = view.findViewById(R.id.userimage);

//        Onclicklisteners

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        ClickImage.setOnClickListener(this);
        UploadImage.setOnClickListener(this);
        Clear.setOnClickListener(this);
        CheckIn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.Click_btn:
                ClickUserImage();
                break;
            case R.id.Upload_Btn:
                UploadUserImage();
                break;
            case R.id.Check_in:
                CheckIn();
                break;
            case R.id.Clear_Sign:
                ClearSignature();
                break;
        }
    }

    private void ClickUserImage() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

            if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

                Toast.makeText(getContext(), "Permission Denied", Toast.LENGTH_LONG).show();
                ActivityCompat.requestPermissions((Activity) getContext(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);

            } else {

                BringImagePicker();

            }

        } else {

            BringImagePicker();
        }

    }

    private void BringImagePicker() {
        CropImage.activity()
                .setGuidelines(CropImageView.Guidelines.ON)
                .setAspectRatio(1, 1)
                .start(getActivity());

    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            CropImage.ActivityResult result = CropImage.getActivityResult(data);
            if (resultCode == RESULT_OK) {
                mainuri = result.getUri();
                Userimage.setImageURI(mainuri);
            } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
                Exception error = result.getError();
            }
        }
    }


    private void UploadUserImage() {
    }


    private void ClearSignature() {
        signaturePad.clear();
    }

    private void CheckIn() {
        if (!signaturePad.isEmpty() && mainuri != null) {
            CheckForRoomAvailability();
        } else {
            Toast.makeText(getContext(), "Signature Not null", Toast.LENGTH_SHORT).show();
        }

    }

    private void CheckForRoomAvailability() {
        CheckIn.setEnabled(false);
        final Query Roomavailable = collectionReference.whereEqualTo("Available", "Y").whereEqualTo("Room Type", RoomType).whereEqualTo("Room size", No_of_guest).limit(1);
        Roomavailable.addSnapshotListener(new EventListener<QuerySnapshot>() {
            @Override
            public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
                if (e == null) {
                    if (!queryDocumentSnapshots.isEmpty()) {
                        Toast.makeText(getContext(), "Size" + queryDocumentSnapshots.size(), Toast.LENGTH_SHORT).show();
                        roomAvaibilityViewModels = queryDocumentSnapshots.toObjects(RoomAvaibilityViewModel.class);
                        String RoomId = roomAvaibilityViewModels.get(0).getRoom_documnet_id();
                        MakeRoomNotAvailable(RoomId);
                        UploadUserSignatureProof();
                        CheckIn.setEnabled(true);
                    } else {
                        CheckIn.setEnabled(true);
                        Toast.makeText(getContext(), "No Rooms are avilable", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    CheckIn.setEnabled(true);
                    Toast.makeText(getContext(), "Something Went Wrong", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }

    private void MakeRoomNotAvailable(String roomId) {
        collectionReference.document(roomId).update("Available", "N");
    }

    private void UploadUserSignatureProof() {
        final String random = UUID.randomUUID().toString();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        signaturePad.getSignatureBitmap().compress(Bitmap.CompressFormat.JPEG, 100, baos);
        byte[] data = baos.toByteArray();
        StorageReference storageReference = mstorageRef.getReference();
        storageReference.child(firebaseAuth.getCurrentUser().getEmail()).child("signature" + random + ".jpg").putBytes(data).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                Task<Uri> downloadUrl = taskSnapshot.getStorage().getRoot().getDownloadUrl();
                UploadDetails(downloadUrl);
            }
        });
    }

    private void UploadDetails(Task<Uri> downloadUrl) {
        Map<String, Object> check_in_details = new HashMap<>();
        check_in_details.put("SignatureProof", downloadUrl.toString());
        check_in_details.put("Check_in_status", "Y");
        firebaseFirestore.collection("Check-in Details").document(booking_id).set(check_in_details).addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (task.isSuccessful()) {
                    Toast.makeText(getContext(), "Check-in sucess", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(getContext(), "Check-in sucess", Toast.LENGTH_LONG).show();
                }
            }
        });

    }



}

I have used image cropper library to crop image. Thank you in advance .

Shrey Soni
  • 19
  • 9
  • 1
    You asked this before? You posted much too much irrelevant code. Post only relevant code please. – blackapps Jul 08 '20 at 08:13
  • Tell which statement causes that exception. Find out please. – blackapps Jul 08 '20 at 08:14
  • 1
    Does this answer your question? [What to do on TransactionTooLargeException](https://stackoverflow.com/questions/11451393/what-to-do-on-transactiontoolargeexception) – Walid Jul 08 '20 at 08:15
  • I have gone through stack overflow before and after implementing the solution provided by different peoples still my app crash. – Shrey Soni Jul 08 '20 at 08:20
  • The exception cause when my app goes in background and gallery app comes in foreground – Shrey Soni Jul 08 '20 at 08:27

0 Answers0