0

There is an application, in which I have to take data through JSON and use this data in different parts of my application. What is the best way to do this? I mean, it doesn't seem efficient to me, - to pud data in bundle and then add extras from bundle to different intents. Is there something like shared preferences, but only for my app, so from every place within application I can retrieve the data I need, but this data is not visible to other applications? Thanks!

lomza
  • 9,412
  • 15
  • 70
  • 85

4 Answers4

1

it seems you are searching for android application object.

here is an so post which has the solution you are looking for.

How to declare global variables in Android?

Community
  • 1
  • 1
Samuel
  • 9,883
  • 5
  • 45
  • 57
1

You can use sqlite database, files or Shared preferences, Look at this Android - Data storage or try this Tutorial.

user370305
  • 108,599
  • 23
  • 164
  • 151
1

Shared Prefs are only for your app (unless you change the mode, PRIVATE is the default) and can be accessed from all your activities. If its alot of data you might consider using a SQLite Database.

pumpkee
  • 3,357
  • 3
  • 27
  • 34
1

First, I would not suggest you using shared preferences, if you need efficient way yo get your data. Shared preferences is something to keep your small (i.e boolean or int) values which would actually represent preferences. Why? Because SharedPreferences are slow. I would recommend you to check this out:

  • Use Shared Preferences for primitive data
  • Use internal device storage for private data Use external storage for large data sets that are not private
  • Use SQLite databases for structured storage

That's what Google recommends you to do. If you want your data to be private, I would recommend you to use Mode Private and to keep your data in a hidder ( ./data ) folder in your application package folder. But remember, that if you really want to get something, you actually will get it, so do not keep private server passwords etc there

Vivienne Fosh
  • 1,751
  • 17
  • 24