Save data in SharedPreferences when application is not running
<p>I am using <code>SharedPreferences</code> to store my data. When my application is running data is been saved to <code>SharedPreferences</code> successfully but when i close my application and try to save data in it via <code>Intent Service</code> nothing happened . no data saved to it :</p>

<pre><code>public class TinyDB {

private  SharedPreferences preferences;
private String DEFAULT_APP_IMAGEDATA_DIRECTORY;
private String lastImagePath = "";

public TinyDB(Context appContext) {
    preferences = PreferenceManager.getDefaultSharedPreferences(appContext);
}


public void putString(String key, String value) {
        checkForNullKey(key); checkForNullValue(value);
        preferences.edit().putString(key, value).apply();
    }
}
</code></pre>

<p>I am using its object in <code>onMessageReceive()</code></p>

<pre><code>public void onMessageReceived(RemoteMessage remoteMessage) {
    tinyDb.putString("key","value");
}
</code></pre>

<p>The main point that i want to make sure that i want to save value when app is not running. When app is running everything is fine. </p>

<p>I also want to know what class or Activity is best for initializing the object of TinyDB , and i should make it static or not ?</p>