class SharePreviewActivity : AppCompatActivity() { companion object { private const val EXTRA_MESSAGE = "message" fun newInstance(context: Context, message: String? = null) = Intent(context, SharePreviewActivity::class.java).apply { putExtra(EXTRA_MESSAGE, message) } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_share_preview) setSupportActionBar(toolbar) val message = intent.getStringExtra(EXTRA_MESSAGE) }}
startActivity(SharePreviewActivity.newInstance(context))startActivity(SharePreviewActivity.newInstance(context, "Hello"))
References: