 <p>The code you need is as following:</p> <pre><code>Context context = instrumentation.getTargetContext(); PreferenceManager.getDefaultSharedPreferences(context).edit().clear().commit(); </code></pre> <p>If your application uses any different shared preferences you may need to clear them too in the following way:</p> <pre><code>context.getSharedPreferences("XXX", Context.MODE_PRIVATE).edit().clear().commit(); </code></pre>