1

We can do that:

val fragment = SomeFragment()
val args = Bundle()
args.putString("Key_Value", "String_Value")
fragment.arguments = args

And we can take it from Fragment like this:

arguments.getString("String_key","Default Value")

My question is can we pass a class object as parameter?

val some_object = SomeClass()
args.put("Key_Value", some_object )

1 Answers1

1

You can pass something that's parcelable (Don't do this with classes like Activities, Fragments etc. ) See this answer: https://stackoverflow.com/a/33649155/7968986

Or pass something that identifies that class, for example it's possible to pass the Classname as a String and then inside the fragment call stuff like startActivity if it's a Activity / Android related class that you shouldn't pass (or parcelize)

See this answer: https://stackoverflow.com/a/39676049/7968986

In general the class is not allowed to be too big if it's parcelized, so in some cases you need other solutions

Merthan Erdem
  • 5,598
  • 2
  • 22
  • 29