-2

im working on my first project in Android Studio & I wonder how to use data from a User Input in another Activity (that is not the following Activity)

 ItemAdapter.OnClickListener {
            override fun onClick(position: Int, item: EmpUserClass) {
                val intent = Intent(this@LoginActivity, OverviewActivity::class.java)
                intent.putExtra(USER_DETAILS, item)
                startActivity(intent)
            }

works fine on the next Activity. How can i manage it on following Activities?

2 Answers2

0

There are two possible answers to your question:

  • If the user only needs to be persisted for the current session (while the app is running), the better solution would be to put it in a singleton class that you'll use throughout your app (something like a UserManager class for instance)
  • If this data needs to be persisted between launches (if you want the user to stay connected when restarting the app, for instance), you should use either shared preferences or Room, depending on the complexity of your data
Valentin Rocher
  • 11,667
  • 45
  • 59
  • or, probably the more official way, is to just make use of single activity architecture – a_local_nobody Apr 21 '21 at 06:51
  • Thanks for your replies. Actually i m using an SQLite Database, as i have to hold the Users. I m getting errors when i want to use data in further Activties. – Rudy Rüssel Apr 21 '21 at 07:06
0

I would suggest you to create some kind of cache that would be Singleton and store the data there, and at the end use it when you need it.

AceStan
  • 109
  • 1
  • 1
  • 7