android


Is it possible to delete MODE_PRIVATE Android SharedPreferences from another activity?


I have two activities, HomePageActivity (home page) ListActivity (list of data), the datas of the ListActivity come from SharedPreferences. I would like to delete the SharedPreferences of ListActivity from the HomePageActivity (for example to resynchronize local data with remote data). Is it possible to do that from the HomePageActivity?
Here is the way the data are stored in SharedPreferences in ListActivity:
SharedPreferences mPrefs = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = mPrefs.edit();
prefsEditor.putString(AppUser.SHARED_MYLIST, myList);
prefsEditor.apply();
And I would like to be able to remove these data from HomePageActivity.
Try
getPreferences("myPrefsName", MODE_PRIVATE)
in both your activities. You will get the same SharedPreferences instance.
public class MainActivity extend AppCompatActivity{
protected void onCreate(#Nullable Bundle savedInstanceState) {
SharedPreferences mPrefs = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = mPrefs.edit();
prefsEditor.putString(AppUser.SHARED_MYLIST, myList);
prefsEditor.apply();
}
}
public class MainActivity2 extend AppCompatActivity{
protected void onCreate(#Nullable Bundle savedInstanceState) {
SharedPreferences mPrefs = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = mPrefs.edit();
prefsEditor.remove(AppUser.SHARED_MYLIST).apply();
}
}

Related Links

How to Move Android layout's background loop
Deleting ImageView by dragging to corner or over a button
How can I create tilt shift alpha mask on the fly?
Inflating LinearLayout for CursorAdapter
Android wait for GoogleMap.OnMyLocationChangeListener
UIView equivalent in Android
Parse Push Notification delete invalid device token?
How do I make a beep sound in Android using Delphi and the API?
Pasing data through app after install without launching
Covering android ImageView
Expand all entries in tree with one click
Bluetooth Low Energy: gattCharacteristic.getDescriptor() returns null
Google Plus Get Friends List for android application
Reuse last facebook login session after reopening application
how to extract integer value on textview to another integer inside listview onclicklistener
RecyclerView: Inconsistency detected. Invalid item position

Categories

HOME
uml
twitter-bootstrap-3
cheerio
jax-rs
mysql-workbench
jwplayer
requirements
spring-data-redis
polling
p2p
augeas
google-schemas
enthought
plist
redis-sentinel
capistrano3
git-extensions
foreign-keys
mapstruct
topology
simpleitk
aggregation
xunit
strongname
mount
ckfinder
stackexchange
spotipy
ceylon
google-earth
anki
r-grid
fstream
carriage-return
jwplayer6
servicestack-text
xajax
salesforce-communities
zoomify
opensmpp
apache-stanbol
laravel-elixir
smoothstate.js
facebook-social-plugins
vaadin-elements
mesosphere
bluez
podscms
pair-programming
azure-cli
oracleclient
gameplay-kit
lrs
async.js
spring-cloud-feign
signalr.client
x-tag
i386
observablecollection
clipboard.js
php-socket
ellucian-scribe
aspen
grgit
flock
lasso
eoferror
jdk1.7
diff3
cosine-similarity
easyrtc
paw
ss7
grails-domain-class
extjs2
gae-quotas
light
jammer
poker
onload-event
idn
vfs
subproject
relative
flex-mobile
rmdir
w3c-geolocation
xui
dataform
codebase
mtu
photolibrary
dot-emacs
lxr
product-management

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile