0

I've recently been making a very data driven application in which I use a lot of arrays. I've tried searching for a solution, but the problem is quite difficult to word concisely so I haven't been able to find an answer. If there's an obvious one I apologize beforehand.

Currently I load a set of 30 arrays from multiple pre-made databases during an initial class, and I use intents to move this set of arrays back and forth between my classes. The problem is, this results in very long extra sequences of code in every single one of my classes. To give an example, after the initial screen I have to enter the code in every class:

Intent intent = new Intent (getApplicationContext(), NextScreen.class);
intent.putExtra("array1", Array1);
// ... 30 more arrays

and then

Bunble b = getIntent().getExtras();
Array1 = b.getStringArray("array1");
// ... 30 more arrays

I was hoping maybe there would be a way to store all the arrays in some resource or class to just reference later.

Mat
  • 202,337
  • 40
  • 393
  • 406

3 Answers3

1

I suggest your create a Class that holds all your information , then make this class Parcelable so it can move throught activities : Parcelable example .

Rick
  • 1,124
  • 9
  • 13
0

Instead of using arrays, create a class with static vector or arraylist. create setter and getter methods which will update your arrays. and directly call these methods from multiple classes,you don't need to pass values. just store them in one class, and use the same class, to read write from multiple places

AAnkit
  • 27,299
  • 12
  • 60
  • 71
0

Try using a singleton class. This will be like a "Model" class in MVC patter.

However, exercise caution when using this, as per this discussion:

Singletons vs. Application Context in Android?

Community
  • 1
  • 1
Gopal Nair
  • 830
  • 4
  • 7