How can I backup SharedPreferences to SD card?

前端 未结 4 949
盖世英雄少女心
盖世英雄少女心 2020-12-08 08:55

I saw in a lot of places that it\'s a problem to copy the SharedPreferences file to the sd card because every manufacturer place it somewhere else.

I want to backup

4条回答
  •  醉酒成梦
    2020-12-08 08:59

    try {
        input = new FileInputStream(src1);
        SharedPreferences.Editor prefEdit =   getSharedPreferences("prueba100", MODE_PRIVATE).edit();
        prefEdit.clear();
        Map entries = XmlUtils.readMapXml(input);
        for (Map.Entry entry : entries.entrySet()) {
            putObject(prefEdit, entry.getKey(), entry.getValue());
        }
        prefEdit.apply();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    

提交回复
热议问题