Skip to content

Type-safe intents and bundles for activities and fragments.

Notifications You must be signed in to change notification settings

MrBoomDeveloper/SafeArgsNext

Repository files navigation

SafeArgsNext

A type-safe alternative to your boilerplate code.

Usage examples

Use arguments

class MyActivity : AppCompatActivity(), SafeArgsActivity<MyActivity.Args> {
    
	override fun onCreate(savedInstanceState: Bundle?) {
		super.onCreate(savedInstanceState)
		safeArgs?.let { args: Args -> Toast.makeText(this, 
			"Name: ${args.name}, age: ${args.age}", 
			Toast.DURATION_LONG).show() 
		}
	}
    
	data class Args(val name: String, val age: Int)
}

Put arguments into activity

startActivity(SafeArgsIntent(this, MyActivity::class, 
	MyActivity.Args(name = "MrBoomDev", age = 17)
))

Put arguments into fragment

supportFragmentManager.beginTransaction()
	.setReorderingAllowed(true)
	.add(id, MyFragment::class, safeArgs, "MyFragment")
	.commit()