regulaforensics / DocumentReader-Android

Android Framework for reading and validation of identification documents
64 stars 26 forks source link

Unable to navigate to the fragment on IDocumentReaderCompletion -> DocReaderAction.COMPLETE #42

Closed dsshreya closed 2 years ago

dsshreya commented 2 years ago

Hi. i am trying to navigate to another fragment using android's navigation API via `findNavController().navigate but it throws the error : E/Parser: Missed LEX value I/FragmentNavigator: Ignoring navigate() call: FragmentManager has already saved its state

and it never goes to the next fragment screen.

Below is the code : private val completion = IDocumentReaderCompletion { action, results, error -> when (action) { DocReaderAction.COMPLETE -> { if (Instance().functionality().isManualMultipageMode) { if (results?.morePagesAvailable != 0) { Instance().startNewPage() Handler(Looper.getMainLooper()).postDelayed({ showScanner() }, 100) return@IDocumentReaderCompletion } else { Instance().functionality().edit().setManualMultipageMode(false).apply() } } findNavController().navigate( ScanPassportFragmentDirections.actionScanPassportFragmentToConfirmPassportDetailsFragment( DocumentReaderResult(results) ) ) } DocReaderAction.CANCEL -> { if (Instance().functionality().isManualMultipageMode) Instance().functionality().edit().setManualMultipageMode(false).apply() Toast.makeText(requireContext(), "Scanning was cancelled", Toast.LENGTH_LONG).show() } DocReaderAction.ERROR -> { Toast.makeText(requireContext(), "Error:$error", Toast.LENGTH_LONG).show() } } }

I notice that in the sample app you do something similar where you get the results, do some logic and then progress to a results screen. the only difference is that i see that you are using activities to navigate to the result screen and not fragments

Is there a way to navigate to a new fragment? we use one activity for our whole app and use navigation fragments for each screen.

dsshreya commented 2 years ago

The issue resolved for me, by creating a LiveData and setting a value for the same in DocReaderAction.COMPLETE and navigate to designated fragment when its observed. private var isScanCompleteLiveData : MutableLiveData = MutableLiveData() private val completion = IDocumentReaderCompletion { action, results, error -> when (action) { DocReaderAction.COMPLETE -> { ...... isScanCompleteLiveData.postValue(DocumentReaderResult(results)) }

override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState)
isScanCompleteLiveData.observe(viewLifecycleOwner) {} }