androidsharedpreferencesandroid-serviceandroid-2.2-froyo

Can I get data from shared preferences inside a service?


I'm developing an android application. I'm using android 2.2

In my application I am capturing GPS data and sending it to service with the 1 hour time interval. If user exits from application it's also working (it is required).

I'm using 2 services (User defined), one for capturing GPS data and other for sending to the server.

Here my doubt


Solution


  • I find the solution.
    Inside a service we call the following method to get the shared preferences

    myapp.bmodel.getApplicationContext().getSharedPreferences("myPrefs_capture_gps_per_hour", Context.MODE_PRIVATE);
    


    In the above code myapp is a object of the application class which is derived from Application