close

[Solved] Java solution for “startActivityForResult(Intent,int) in Fragment has been deprecated” when opening external URL?

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Java solution for “startActivityForResult(Intent,int) in Fragment has been deprecated” when opening external URL? in java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Java solution for “startActivityForResult(Intent,int) in Fragment has been deprecated” when opening external URL Error Occurs?

Today I get the following error Java solution for “startActivityForResult(Intent,int) in Fragment has been deprecated” when opening external URL? in java.

How To Solve Java solution for “startActivityForResult(Intent,int) in Fragment has been deprecated” when opening external URL Error ?

  1. How To Solve Java solution for “startActivityForResult(Intent,int) in Fragment has been deprecated” when opening external URL Error ?

    To Solve Java solution for “startActivityForResult(Intent,int) in Fragment has been deprecated” when opening external URL Error In side the fragment, I created ActivityResultLauncher.

  2. Java solution for “startActivityForResult(Intent,int) in Fragment has been deprecated” when opening external URL?

    To Solve Java solution for “startActivityForResult(Intent,int) in Fragment has been deprecated” when opening external URL Error In side the fragment, I created ActivityResultLauncher.

Solution 1


Below answer may help to someone…. But this is not readymade solution to above question.

I have faced lot of issue when I try to get result from activity to fragment. Finally I found below solution.

In side the fragment, I created ActivityResultLauncher.

var myActivityResultLauncher: ActivityResultLauncher<Intent> = registerForActivityResult<Intent, ActivityResult>(
        ActivityResultContracts.StartActivityForResult(),
        ActivityResultCallback<ActivityResult> {
            // ToDO: 
            if (it.resultCode == AppCompatActivity.RESULT_OK) {

            }
        }
) as ActivityResultLauncher<Intent>

And when I start the activity I used below code.

myActivityResultLauncher.launch(myIntent)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment