Can I get data from shared preferences inside a service?

前端 未结 5 1625
不思量自难忘°
不思量自难忘° 2020-12-10 00:46

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

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 00:58

    There are two ways to create instance of SharedPreference:

    Case 1:

    SharedPreferences preferences = activity.getSharedPreferences("", MODE_PRIVATE);
    

    Case 2:

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    

    Notice if you create a preference with the same name (case 1) or same context (case 2) even at different places, it's still the same, and can share data, obviously.

提交回复
热议问题