Jeff
Jeff

Reputation: 2248

Using Android navigation controller and finishing the calling activity

I have an activity that is using the navigation component to flow through my fragments to get info from the user in a wizard style. I have a dead end fragment in my flow where I tell the user why they can't continue and I want to provide a done/cancel button that finishes the activity that the nav controller is in and leaves the user at the screen they left off on.

I tried adding the activity they launch the flow from as an action destination but that launches the activity as a new activity and isn't where the user left from.

I can grab the activity from the fragment and call finish() on that activity from the button click but that didn't seem like the way one is supposed to use the nav graph. Am I wrong? Is there a way to say in a nav graph direction to just exit the everything?

Upvotes: 2

Views: 2401

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 200080

There's no navigate() operation that will pop activities off the stack - the only back stack that the NavController is aware of is the internal back stack it manages.

If you want to finish an activity, call finish() on your activity.

Upvotes: 5

Related Questions