0

I have seen this post on the finish() keyword in android What is Activity.finish() method doing exactly?

..but it couldn't find anything that answered my question.

If finish() is called on an activity, will the next activity in the stack be invoked? What if we started that activity for a result from another activity--will onActivityResult() of that other activity be invoked rather than the next activity in the stack? What takes priority over another? I couldn't really find much on these kind of questions.

Thanks!

CodingChap
  • 1,088
  • 2
  • 10
  • 23

1 Answers1

0

if you start ActivityB from ActivityA and if you call finish() from ActiivityB ,ActivityB will be removed from stack,ActivityA will be on top of stack.

if you start ActivityB from onActivityResult() of ActivityA,when you finish ActivityB again ActivityA will be on top of stack.

onActivityResult() will not be invoked because onActivityResult() in just method belongs to ActivityA . so stack is all about activity stack.

androidLearner
  • 1,654
  • 1
  • 7
  • 13
  • Hi, thank you for your response. Here however: "if you start ActivityB from onActivityResult()" I mean starting activity B using startActivityForResult, and then retrieving the result in onActivityResult in activity A. – CodingChap May 30 '21 at 16:54
  • in that case ,if you finish() ActivityB somewhere ,onActivityResult() will be called from ActivityA with result code "Result canceled".@CodingChap – androidLearner May 30 '21 at 18:24
  • I guess, but if we set the result to result_ok from activity B, it would return result_ok in activity A. Thanks. – CodingChap May 30 '21 at 19:00