0

I am recording/selecting a video in my RecordVideo.java activity. Once the video is recorded/selected the I press the upload button and go to the PostActivity.java file. But once I'm in there for some reason onActivityResult isn't being called. I tried to toast and Log.d for some type of error or info but nothing came up.

I checked the answer on here to the same problem I'm having but none of them worked for me. Can someone please help ?

RecordVideo.java:

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

    if (requestCode == REQUEST_CODE_VIDEO_CAPTURE && resultCode == RESULT_OK && data.getData() != null) {

        videoUri = data.getData();
        videoView.setVideoURI(videoUri);
        videoView.start();

    } else if (requestCode == 5 && resultCode == RESULT_OK && data != null && data.getData() != null) {

        videoUri = data.getData();
        videoView.setVideoURI(videoUri);
        videoView.start();
    }

    super.onActivityResult(requestCode, resultCode, data);
}

private void uploadUserVideo(Uri videoUri) {

    if (videoUri != null) {

        Intent intent = new Intent(RecordVideo.this, PostActivity.class);
        intent.putExtra("videoUri", videoUri.toString());
        startActivity(intent);
        finish();
    } else {

        Toast.makeText(this, "It's null", Toast.LENGTH_SHORT).show();
    }
}

PostActivity.java:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_post);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        //videoUri = extras.getInt(videoUri);
        videoUri = Uri.parse(extras.getString("videoUri"));
        //Toast.makeText(this, "It's not null", Toast.LENGTH_SHORT).show();

    } else {
        // handle case
        Toast.makeText(this, "Post null", Toast.LENGTH_SHORT).show();
    }

    videoView = findViewById(R.id.video_added);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(videoView);
    videoView.setMediaController(mediaController);

    close = findViewById(R.id.close);
    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            startActivity(new Intent(PostActivity.this, MainActivity.class));
            finish();
        }
    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

    Log.d("TAG3", "I'm here." + requestCode);

    if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) {

        videoUri = data.getData();
        videoView.setVideoURI(videoUri);
        videoView.start();

        Toast.makeText(this, "No problem.", Toast.LENGTH_SHORT).show();

    } else {

        Toast.makeText(this, "A problem.", Toast.LENGTH_SHORT).show();
    }

    super.onActivityResult(requestCode, resultCode, data);
}
His R.H
  • 19
  • 1
  • 5
  • 1
    onActivityResult will get called when you startActivityForResult but you just used startActvity – Ammar Abdullah Aug 22 '22 at 08:04
  • Yes, just change the `startActivity` call(s) to `startActivityForResult` – user3738870 Aug 22 '22 at 08:05
  • I changed all of them in my RecordVideo file but it's still the same problem – His R.H Aug 22 '22 at 08:08
  • [onactivityresult-method-is-deprecated-what-is-the-alternative](https://stackoverflow.com/questions/62671106/onactivityresult-method-is-deprecated-what-is-the-alternative),, it's better to implement the new ways. – Nitish Aug 22 '22 at 08:40

0 Answers0