You donβt need Activity to save preferences, just Context . In your class that extends AppWidgetProvider , you should get the context in all relevant methods, such as onUpdate and onDeleted .
Then you can use the PreferenceManager to get the preference object and store what you need in it, for example:
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String value = prefs.getString("key-string", null); if(value != null) {
As a side note, you mention that you thought you were using files, but didn't want for performance reasons. SharedPreferences objects actually end up using simple files, they are just managed for you by Android. If you intend to access it often, you still need to be careful about performance. The same is true for SQLite DB, as these are just files.
source share