I'm trying to pass data use putExtra function.
My goal is described in the picture below.
I set a button click listener with out putExtra in First Activity like this;
downloadButton?.setOnClickListener {
val toSendProjectListIntent = Intent(this, LocalProjectListActivity::class.java)
toSendProjectListIntent.putExtra("download", downloaded)
startActivity(toSendProjectListIntent)
}
And the RescyclerView in Second Activity is;
val projectList = ArrayList<ProjectListDataModel>()
val downloadedProjectList = intent.getParcelableArrayListExtra<ProjectListDataModel>("download")
localProjectAdapter = LocalProjectsRecyclerAdapter(projectList, this)
projectListView.adapter = localProjectAdapter
projectListView.setHasFixedSize(true)
projectListView.layoutManager = LinearLayoutManager(this)
}
Question is,
I put val projectList = ArrayList<ProjectListDataModel>
to set empty the Main activity, when I open the app.
After that, I go the Second Activity and select the list by button click.
However, I don't have idea, how to put the selected lists in the localProjectAdapter
. One condition is, when we click the download button, the activity shouldn't be changed.. should be staying at the Second activity.
Moreover, Do you think this is right way? I'm not sure my choice to use the putExtra and parcelable function :(
Any idea?