 <p>Do not extend Activity class in AppPreferences. and remove the <code>onCreate()</code> method.</p> <p>Do like this way.</p> <pre><code>public class AppPreferences extends Activity { private SharedPreferences settings = null; AppPreferences(Context context) { settings = context.getSharedPreferences(LOGIN_CREDENTIALS, MODE_PRIVATE); } ...//Rest of your code. } </code></pre> <p>In Login activity.</p> <pre><code>appPreferences = new AppPreferences(this); </code></pre>