0

We minimize the application, the activity is unloaded from memory, we return to the application and crash (it was not possible to recreate the data from the constructor). Is it possible to transfer the listener through the bundle? (So that it is recreated along with the activity)

code example:

class MyBottomSheetDialogFragment (
    val data: Data,
    val clickListener: () -> Unit
) : BottomSheetDialogFragment() {
    
    
    //using clickListener
}



MyBottomSheetDialogFragment({
    //clicked listener lambda
}).show(fragmentManager, "tag").show()
SKULL
  • 885
  • 8
  • 15
  • What does "the activity is unloaded from memory" mean?. By the way can you show the Data class as well. From your code, I guess from activity, user clicks a button, then you display the bottom dialog. Then they minimize the app, next time they open again, the app might recreate the activity (including the bottom dialog), but the data and listener is null. So you want to find a solution to keep this data and the listene after recreating activity. Is that correct? – Son Truong Nov 24 '20 at 04:07

1 Answers1

0

Check Callback to a Fragment from a DialogFragment

No clean solution has been achieved, but several approaches have been proposed.

miel3k
  • 211
  • 3
  • 3