-1

Is it possible to call startActivityForResult() from non Activity class to get the results?

  • There are lots of answer for this _topic_ – Piyush Nov 20 '19 at 10:42
  • **YES.** Please refer https://developer.android.com/training/basics/intents/result – sanjeev Nov 20 '19 at 10:42
  • You'll need a reference to an `Activity` at least. Practically it probably makes sense to call it from an `Activity` though so you can also use the `onActivityResult` callback. – PPartisan Nov 20 '19 at 10:44
  • pass the activity as a parameter to that class, and using that call onActivityResult. – Haider Saleem Nov 20 '19 at 11:01
  • Does this answer your question? [use startActivityForResult from non-activity](https://stackoverflow.com/questions/2848775/use-startactivityforresult-from-non-activity) – Boken Nov 30 '19 at 00:26

2 Answers2

1

Yes it is poosible

You need an Activity on order to receive the result.

If its just for organisation of code then call other class from Activty class.

 public class Result {
 public static void activityResult(int requestCode, int resultCode, Intent data){
      ...
 }
 }

 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   Result.activityResult(requestCode,resultCode,data);
    ...
}
Anand Gaur
  • 225
  • 2
  • 10
0

You can call startActivityForResult from non-activity classes provided by calling activity context and you can get the result in the same activity within onActivityResult override method.

bidhu
  • 16
  • 1