AndroidDev
AndroidDev

Reputation: 189

How to save values to particular files using activity & how should it access using service in android?

I am developing an android application. In that application I want to save a particular value which I may get from any activity of my application. Now I want to use that value for giving to my service which is running in background (service starts upon boot of the device). How should I proceed for that? Thanks in advance.

Upvotes: 0

Views: 65

Answers (4)

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33534

There are few ways to do it...

1. Store the values in Shared Preference.

2. Store it into a Property file.

3. Store it into a SQLite DB which ships with Android. (SQLite is really a very light DB, but still in this case it will be an overkill)

Upvotes: 0

Alexander Fuchs
Alexander Fuchs

Reputation: 1358

If you want to store the value temporarily while runtime of the service, you have to create a static variable in it

otherwise use SharedPreferences

Upvotes: 0

Ryan Gray
Ryan Gray

Reputation: 824

Shared Preferences. If it's a regular data type. Should it be an object or ADT, you can do this via Intent objects. You could have your "value/object" implement the serializable interface and then encapsulate it inside of an Intent object. You can easily pass that Intent to your service and vice versa.

Upvotes: 0

sataniccrow
sataniccrow

Reputation: 372

You could use SharedPreferences and save there your value.

Upvotes: 1

Related Questions