Repository: google/android-fhir
Issue: Data Capture Gallery App crashes when configuration is changed (eg: language or orientation change)

**Describe the bug**

Data Capture Gallery App crashes when device configuration changes (eg:  language is changed and user comes back to the app or Orientation is changed) while user is on Questionnaire Fragment.

**Component**
SDC gallery app

**To Reproduce**
Steps to reproduce the behavior:
1. Go to 'Patient Registration page in the SDC gallery app
2. Press home and go to the Language Setting in Settings App.
3. Change device language.
4. Navigate back to the SDC gallery app from recent apps

**Expected behavior**
The app should show page without any crash. 

**Device Logs**
2021-05-17 18:28:06.308 3344-3344/com.google.android.fhir.datacapture.gallery D/AndroidRuntime: Shutting down VM
2021-05-17 18:28:06.325 3344-3344/com.google.android.fhir.datacapture.gallery E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.google.android.fhir.datacapture.gallery, PID: 3344
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at androidx.navigation.NavArgsLazy.getValue(NavArgsLazy.kt:52)
        at androidx.navigation.NavArgsLazy.getValue(NavArgsLazy.kt:34)
        at com.google.android.fhir.datacapture.gallery.QuestionnaireContainerFragment.getArgs(Unknown Source:4)
        at com.google.android.fhir.datacapture.gallery.QuestionnaireContainerFragment.onCreateView(QuestionnaireContainerFragment.kt:59)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2952)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
        at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1647)
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3124)
        at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:3061)
        at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:2977)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:546)
        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
        at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1647)
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3124)
        at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3068)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:501)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:210)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1435)
        at android.app.Activity.performStart(Activity.java:8024)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3475)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
     Caused by: java.lang.IllegalArgumentException: Required argument "questionnaireTitleKey" is missing and does not have an android:defaultValue
        at com.google.android.fhir.datacapture.gallery.QuestionnaireContainerFragmentArgs$Companion.fromBundle(QuestionnaireContainerFragmentArgs.kt:33)
        at com.google.android.fhir.datacapture.gallery.QuestionnaireContainerFragmentArgs.fromBundle(Unknown Source:2)
        at java.lang.reflect.Method.invoke(Native Method) 
        at androidx.navigation.NavArgsLazy.getValue(NavArgsLazy.kt:52) 
        at androidx.navigation.NavArgsLazy.getValue(NavArgsLazy.kt:34) 
        at com.google.android.fhir.datacapture.gallery.QuestionnaireContainerFragment.getArgs(Unknown Source:4) 
        at com.google.android.fhir.datacapture.gallery.QuestionnaireContainerFragment.onCreateView(QuestionnaireContainerFragment.kt:59) 
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2952) 
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518) 
        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282) 
        at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112) 
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1647) 
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3124) 
        at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:3061) 
        at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:2977) 
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:546) 
        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282) 
        at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112) 
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1647) 
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3124) 
        at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3068) 
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251) 
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:501) 
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:210) 
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1435) 
        at android.app.Activity.performStart(Activity.java:8024) 
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3475) 
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221) 
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201) 
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7656) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
2021-05-17 18:28:06.350 3344-3344/com.google.android.fhir.datacapture.gallery I/Process: Sending signal. PID: 3344 SIG: 9


**Would you like to work on the issue?**
Yes

Changed files:
datacapturegallery/src/main/java/com/google/android/fhir/datacapture/gallery/QuestionnaireContainerFragment.kt

diff --git a/datacapturegallery/src/main/java/com/google/android/fhir/datacapture/gallery/QuestionnaireContainerFragment.kt b/datacapturegallery/src/main/java/com/google/android/fhir/datacapture/gallery/QuestionnaireContainerFragment.kt
index 3e34d755f..984228c75 100644
--- a/datacapturegallery/src/main/java/com/google/android/fhir/datacapture/gallery/QuestionnaireContainerFragment.kt
+++ b/datacapturegallery/src/main/java/com/google/android/fhir/datacapture/gallery/QuestionnaireContainerFragment.kt
@@ -54,11 +54,10 @@ class QuestionnaireContainerFragment : Fragment() {
   ): View? {
     super.onCreate(savedInstanceState)
     _binding = FragmentQuestionnaireContainerBinding.inflate(inflater, container, false)
-    arguments =
-      bundleOf(
-        QUESTIONNAIRE_FILE_PATH_KEY to args.questionnaireFilePathKey,
-        QUESTIONNAIRE_RESPONSE_FILE_PATH_KEY to args.questionnaireResponseFilePathKey
-      )
+    requireArguments().putString(QUESTIONNAIRE_FILE_PATH_KEY, args.questionnaireFilePathKey)
+    requireArguments()
+      .putString(QUESTIONNAIRE_RESPONSE_FILE_PATH_KEY, args.questionnaireResponseFilePathKey)
+
     (requireActivity() as AppCompatActivity).supportActionBar?.apply {
       title = args.questionnaireTitleKey
       setDisplayHomeAsUpEnabled(true)