androidkotlinconstructorappcompatactivity

Activity constructor is not assigning value


class CosmosNewsDetailActivity() : AppCompatActivity(), ArticleAppearanceActionListener {
private var newsKey = -1L
private var newsItem: NewsGetAllResponse.NewsGetAllResponseItem? = null

constructor(key: Long, item: NewsGetAllResponse.NewsGetAllResponseItem?) : this() {
    newsKey = key
    newsItem = item
}

newsKey is always at value -1, how do I instantiate this class with these parameters without using intent extras

I can see the value for key in the constructor is correct but never assigned to newsKey


Solution

  • The only Activity constructor that will be used is a zero-argument constructor. Please do something else for getting data to this activity (e.g., Intent extras, shared data managed by a repository) or get rid of this activity (have it be another fragment or composable used by an existing activity).