0

Suppose in an android application, there are 4 activities. The first one 'A', list down orders. The second one 'B', is a form to create new orders. The third one 'C', is a confirmation on what the user has put in 'B'. While the forth one 'D' is an activity that show the loading progress of submitting the order. In normal flow, the user go from A to B to C and to D.

My question is, what should I do so that when its on 'D', and it has been completed, when user press back, it goes directly to 'A'. And when the user is in 'C', the user can press back to go to 'B' (meaning any modification should not alter this). Also, what if 'A' is not the first activity, meaning there is 'E' which start before 'A' and when the user is in 'C' and user press back, it should go to 'A' instead of 'E'.

I would prefer if the solution does not involve fragment. Not that It can't be used, but suppose you can't use it, what would you do? Thanks in advance.

asdacap
  • 738
  • 2
  • 9
  • 15

2 Answers2

1

Probably the best way to handle this is to use startActivityForResult in all your activities. You can set flags to manage the "state" of the Activities. For example, you can set a flag once the user proceeds from "C" to "D" that indicates "C" should "finish" and so should "B"

How to manage `startActivityForResult` on Android?

This is the best way to handle the stack without overriding the "back" button, which is also possible.

Android - How To Override the "Back" button so it doesn't Finish() my Activity?

Generally when you try to control "back" things happen with users that you don't want or expect, and they never tell you. They just stop using your app.

Since you have an "E" activity, it might be more complex. But based on your description, either of the two approaches above should work for you.

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36
0

This is not an answer. But i cant comment cause I don't have enough rep.

You can use:

  • startActivityForResult()
  • LocalBroadcastManager

startActivityForResult() seems better for you cause you have something like a wizard-setup thing.

j4rey
  • 2,582
  • 20
  • 34