I want to start another activity on Android but I get this error:
Please specify constructor invocation; classifier \'Page2\' does not have a companio
How about this to consider encapsulation?
For example:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_contents)
val title = intent.getStringExtra(EXTRA_TITLE) ?: EXTRA_TITLE_DEFAULT
supportFragmentManager.beginTransaction()
.add(R.id.frame_layout_fragment, ContentsFragment.newInstance())
.commit()
}
// Omit...
companion object {
private const val EXTRA_TITLE = "extra_title"
private const val EXTRA_TITLE_DEFAULT = "No title"
fun newIntent(context: Context, title: String): Intent {
val intent = Intent(context, ContentsActivity::class.java)
intent.putExtra(EXTRA_TITLE, title)
return intent
}
}