android - Storing temporary data outside activity lifecycle -


i'd store temporary data. think storing id of selected conversation in messaging application.

this in bundle, in singleton, want stored outside of activity lifecycle. temporary data should behave parceled data in view (i don't want ui responsible storing data)

storing id in memory work, except won't survive system closing application when memory low , restoring application disk when user goes (not sure technical term is)

sharedpreferences work, except don't want data survive reboot.

is there built in mechanism (outside activity lifecycle)?

you can use shared preferences...

private static final string shared_prefs = "any_name"; sharedpreferences preferences = context.getsharedpreferences(shared_prefs, context.mode_private); preferences.edit().putint(key, value).apply(); 

where key can "current_id" , value id selected integer. can store string using putstring() method.

can accessed

sharedpreferences preferences = context.getsharedpreferences(shared_prefs, context.mode_private); preferences.getint(key, 0); 

where key again "current_id" , 0 default value if null returned.

for more shared preferences documentation.

if going use code in activity can use :

sharedpreferences preferences = getsharedpreferences(shared_prefs, context.mode_private); 

no need use context.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -