how to remove shared preference while application uninstall in android

The problem is not with preferences. It's drastically the backup manager! .. since android-23 by default backup as a task stores app's data including preferences to cloud. Later when you uninstall then install newer version you are probably going to use restored preferences. To avoid that, just add this to your manifest (or at least to debug manifest):

<application ...
        android:allowBackup="false">
...
</application>

Read this: http://developer.android.com/guide/topics/data/backup.html

You will also see that if you run Lint under Android > Lint > Security:

lint warning on backup

It's good to mention here that the process of backup is like a blackbox .. you don't know when it starts, and period between checks ... so better for developing to disable it.

==== Update ====

You may get Manifest merger issues after setting allowbackup to false. To fix that issue add:

tools:replace="android:allowBackup"

in the application element. Credit to @shahzain-ali

Alternatively you can clear cache before uninstalling app.

I hope that may help.


SharedPreferences is always deleted along with the app uninstall.

When you uninstall any application all the changes the application have made in your internal memory are revoked, that means your SharedPreference files, Other data files, Database file, Application gets removed automatically by the Android OS.

EDITED: 29/04/15: for >= 21 API refer @Maher Abuthraa 's answer