architecture-samples icon indicating copy to clipboard operation
architecture-samples copied to clipboard

Is it correct to allow back to addtask_frag after saving the task?

Open AlfredoLopezG opened this issue 6 years ago • 1 comments

When i finish a new task then in task list if i press back physical button return me to new task with data if save again duplicate the task. When i edit a task and press back button and i save the task apply the new changes

Is correct that navigation? Because that doesn't allow to exit of the app until return all navigation

AlfredoLopezG avatar Oct 29 '19 20:10 AlfredoLopezG

You're right to question that navigation behavior — it is not ideal UX to allow returning to the AddTaskFragment after saving a task, especially if doing so allows resaving and duplicating data. Let's break this down:

Problem: After saving a task from AddTaskFragment, user is navigated to the TaskListFragment.

But when the user presses the back button, they are taken back to AddTaskFragment.

Pressing save again from this stale screen duplicates the task.

This introduces:

Task duplication

Confusing navigation

User frustration (especially if pressing back doesn’t exit the app)

Expected Behavior: After saving a task:

The AddTaskFragment should be popped from the back stack so that the user cannot return to it via back navigation.

Or navigate in a "replace" style (not "add to back stack").

Recommended Fix (in Navigation Component): When navigating after saving, do not add the transaction to the back stack, for example:

findNavController().navigate( R.id.action_addEditTaskFragment_to_taskListFragment, null, NavOptions.Builder() .setPopUpTo(R.id.addEditTaskFragment, true) .build() ) This:

Navigates to TaskListFragment

Pops AddTaskFragment from back stack

Prevents going back to it

Alternative: Clear Input After Save If for some reason you must allow going back, at least clear the inputs and disable re-submission. But this is not ideal — better to handle it via navigation as above.

Final Recommendation: Yes, it is incorrect to allow navigating back to the add/edit screen after saving. Use NavOptions.setPopUpTo() or finish() in activity-based apps to remove it from back stack after save.

VaradGupta23 avatar Jul 21 '25 06:07 VaradGupta23