0

In activity A I call an API to retrieve list of cities.

Then in activity B there's a button , once the user clicks on that button another activity C will open.Activity C has a drop down list that need to display all cities that i got from activity A.

So my question is how can I access the list from activity A in Activity C without declaring it as public static?

rav
  • 211
  • 5
  • 14

1 Answers1

0

If you don't want to pass data thru activities then you can use a Singleton pattern. So you will be able to get your data from any place in your program and you don't need to make this list serializable.

More details about singleton is here: https://en.wikipedia.org/wiki/Singleton_pattern

Antaaaa
  • 233
  • 3
  • 14
  • Actually in Activity A user will input something then the API will return a list of cities and a manager ID , So the manager ID will be different based on user input , will singleton be okay with that scenario? – rav Jun 29 '20 at 15:06
  • @rav I dont see any issues with it. – Antaaaa Jun 29 '20 at 15:11
  • @rav So basically what your program is doing: 1. Activity A (user write down some data) 2. Activity B (press the button, make the URL request and receives some data) 3. Activity C (show data from Singleton class) – Antaaaa Jun 29 '20 at 15:13