android - Shared preferences on fragment -


i trying use shared preferences on android inside fragment appcompat. says me "the method getdefaultsharedpreferences(context) in type preferencemanager not applicable arguments (preferenciasfragment)" here code:

private void savepreferences(string key, string value) {              sharedpreferences sharedpreferences = preferencemanager.getdefaultsharedpreferences(this);             editor editor = sharedpreferences.edit();             editor.putstring(key, value);             editor.commit();          } 

try this..

use getactivity() instead of this

sharedpreferences sharedpreferences = preferencemanager.getdefaultsharedpreferences(getactivity()); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -