Use SharedPreferences on multi-process mode

前端 未结 7 908
不思量自难忘°
不思量自难忘° 2020-12-13 14:50

I\'ve defined an instance of SharedPreferences that used on multi-process mode.

public class Prefs {

    private static SharedPreferences pref         


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 15:28

    If two processes write data to SharedPreferences, then it might possible all SharedPreferences are reset to default values.

    Also you can try to call clear() on the editor before storing val

    SharedPreferences.Editor sp = settings.edit();
    sp.clear();
    sp.putString("Name", "YourName");
    sp.commit();
    

提交回复
热议问题