If you didn't pass any bundle argument of Double and call arguments.getDouble
on the receiving end, you shall get Zero(0) rather than null. To check if the value are actually passed in, call arguments.containsKey
.
class LocationPickerDialog : DialogFragment() { companion object { private const val TAG = "LocationPickerDialog" private const val EXTRA_LAT = "lat" private const val EXTRA_LNG = "lng" fun newInstance(lat: Double? = null, lng: Double? = null): LocationPickerDialog { val dialog = LocationPickerDialog() val args = Bundle().apply { lat?.let { putDouble(EXTRA_LAT, it) } lng?.let { putDouble(EXTRA_LNG, it) } } dialog.arguments = args return dialog } } override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) val lat = arguments?.run { if (containsKey(EXTRA_LAT)) getDouble(EXTRA_LAT) else null } val lng = arguments?.run { if (containsKey(EXTRA_LNG)) getDouble(EXTRA_LNG) else null } }}