Questions tagged [startactivityforresult]

Questions about starting Activities in Android and in return receive a result from the started activity when it finished.

From Android Documentation: Starting another activity doesn't have to be one-way. You can also start another activity and receive a result back. To receive a result, call startActivityForResult() (instead of startActivity()).

For example, your app can start a camera app and receive the captured photo as a result. Or, you might start the People app in order for the user to select a contact and you'll receive the contact details as a result.

Of course, the activity that responds must be designed to return a result. When it does, it sends the result as another Intent object. Your activity receives it in the onActivityResult() callback.

Note: You can use explicit or implicit intents when you call startActivityForResult(). When starting one of your own activities to receive a result, you should use an explicit intent to ensure that you receive the expected result.

301 questions
1100
votes
14 answers

How to manage startActivityForResult on Android

In my activity, I'm calling a second activity from the main activity by startActivityForResult. In my second activity, there are some methods that finish this activity (maybe without a result), however, just one of them returns a result. For…
Hesam
  • 52,260
  • 74
  • 224
  • 365
90
votes
4 answers

Using startActivityForResult, how to get requestCode in child activity?

I have four activities, say A, B, C and D. My situation is A will start the activity B by startActivityForResult. startActivityForResult(new Intent(this,B.class),ONE); In another situation I will start activity B with a different request code,…
Jithin
  • 1,745
  • 4
  • 18
  • 25
88
votes
2 answers

Check If Activity Has Been Called for Result

Is it possible to know if some activity has been called for result, using startActivityForResult() or if was only started using startActivity()? I need to control this, if its called for result the behaviour will be different.
TiagoM
  • 3,458
  • 4
  • 42
  • 83
16
votes
2 answers

New result API error : Can only use lower 16 bits for requestCode

Today I switched to the new ResultAPI and I faced this error: java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode at androidx.fragment.app.FragmentActivity.checkForValidRequestCode(FragmentActivity.java:715) at…
11
votes
2 answers

Android: requestCode and resultCode

I'm wondering if I am understanding the concepts of requestCode and resultCode properly? Basically, I have an arbitrary integer (the requestCode) associated with an activity. For example, in the Notepad tutorial, we have private static final int…
Tianxiang Xiong
  • 3,887
  • 9
  • 44
  • 63
11
votes
1 answer

deprecated OnActivityResult() in androidx

OnActivityResult() is deprecated in androidx. I took reference from below…
10
votes
0 answers

How to get handle update result of in-App updates

Issue, 'onActivityResult(Int, Int, Intent?): Unit' is deprecated. Deprecated in Java As per in-app update docs, the given method requires onActivityResult but that is deprecated. I can't find any details on how to use registerForActivityResult for…
9
votes
5 answers

Android receive value from onActivityResult and set it to a Button

With this code, I can easily insert dynamically some layouts. The layout contains a Button, which I want to launch startActivityForResult. Now when I get the result (text), I want to set it on the Button. btnAggiungiCampo.setOnClickListener(new…
9
votes
4 answers

Android: setResult not returning result to Parent Activity

I have started a child activity from parent activity using startActivityForResult. After performing required functions in child activity I am setting result using setResult. But I am not getting result at parent activity from child activity. Heres…
8
votes
6 answers

startActivityForResult() vs getActivity().startActivityForResult() in Android Fragment

What the differences between startActivityForResult() vs getActivity().startActivityForResult() in Android Fragment? And what is the behaviour differences in onActivityForResult() when called in Fragment?
j.elmer
  • 1,441
  • 2
  • 17
  • 36
8
votes
3 answers

Fatal Exception: java.lang.RuntimeException: Failure from system

I am getting this exception on crashlytics report frequently don't know why? Fatal Exception: java.lang.RuntimeException: Failure from system at android.app.Instrumentation.execStartActivity(Instrumentation.java:1547) at…
Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
8
votes
3 answers

Android PlacePicker closes 2 seconds after launch

Unfortunately I couldn't find an answer at Android Place Picker closes immediately after launch. For me the PlacePicker launches, shows location as Unknown and then returns with the resultCode 2. To reaffirm some truths: My app has two activities…
7
votes
4 answers

finish() not closing activity when called after the first run

I have three activities MessagesAttachPhotoActivity MessageGalleryFolderSelectorActivity ImagePickerActivity MessagesAttachPhotoActivity calls MessageGalleryFolderSelectorActivity with startActivityForResult().…
6
votes
1 answer

How to listen a startActivityForResult call when using FlutterPlugin?

I'm developing a Flutter Plugin for Android using Java. When i call the MethodChannel, I need to call another Android Intent. If I was using an native activity, it would be simple since I can call startActivityForResult and implement the method…
6
votes
3 answers

How to use registerForActivityResult correctly? Getting "LifecycleOwners must call register before they are STARTED"

I use registerForActivityResult just like : package com.example.livedata import android.Manifest import android.app.Activity import android.app.AlertDialog import android.app.Dialog import android.content.ActivityNotFoundException import…
1
2 3
20 21