I migrated to Navigation Components and since I use Fragments now, I do no longer call onActivityResult() in my Fragment.
I defined the arguments that I pass to AddEditTaskFragment and want to send the modified arguments back to the TodayFragment. Since onViewCreated() is called every time I navigate to the TodayFragment, I want to check if I am actually passing arguments to it to save the Task in my DB then.
Since AddEditTaskFragmentArgs.fromBundle(getArguments()) != null does not work, what is the recommended way to check if a fragment is receiving arguments?
This is how I navigate back to the calling fragment.
AddEditTaskFragmentDirections.ActionAddEditTaskFragmentToHomeFragment action = AddEditTaskFragmentDirections.actionAddEditTaskFragmentToHomeFragment();
action.setTitle(title);
if (id != -1) action.setId(id);
action.setPriority(priority);
action.setAddanote(duedate);
action.setDuedate(remindme);
action.setRemindme(addanote);
action.setModeEdit(modeEdit);
Navigation.findNavController(getView()).navigate(action);
Now I want todo something like:
if (AddEditTaskFragmentArgs.fromBundle(getArguments()) != ...?) {
// Receive data from action
String title = AddEditTaskFragmentArgs.fromBundle(getArguments()).getTitle().trim();
int priority = AddEditTaskFragmentArgs.fromBundle(getArguments()).getPriority();
String duedate = AddEditTaskFragmentArgs.fromBundle(getArguments()).getDuedate();
String remindme = AddEditTaskFragmentArgs.fromBundle(getArguments()).getRemindme();
String addanote = AddEditTaskFragmentArgs.fromBundle(getArguments()).getAddanote().trim();
boolean modeEdit = AddEditTaskFragmentArgs.fromBundle(getArguments()).getModeEdit();
int id = AddEditTaskFragmentArgs.fromBundle(getArguments()).getId();
Task task = new Task(title, addanote, priority, duedate, remindme);
taskViewModel.insert(task);
Toast.makeText(getContext(), "Task saved.", Toast.LENGTH_SHORT).show();
}