title: How to keep the app logged in unless the user forces log out
body: <p>I'm learning android and I have created an app with register and login options. Now I need to configure it to keep the user logged unless he logs out.
  I've been told to use Shared Preferences, so I have used this code, but it doesnt seem to be working, it still logs out after some minutes.</p>
  
  <pre><code>public class PreferenceData 
  {
    static final String PREF_USER_ID = "user_logged_in";
  
    public static SharedPreferences getSharedPreferences(Context ctx) 
    {
       return PreferenceManager.getDefaultSharedPreferences(ctx);
    }
  
    public static void setUserLoggedIn(Context ctx, boolean userLoggedIn) 
    {
       Editor editor = getSharedPreferences(ctx).edit();
       editor.putBoolean(PREF_USER_ID, userLoggedIn);
       editor.commit();
    }
  
    public static boolean getUserLoggedIn(Context ctx) 
    {
       return getSharedPreferences(ctx).putBoolean(PREF_USER_ID);
    }
  }
  </code></pre>
  
  <p>Should I add something to fix the problem?</p>