public void backupSMS(View v) { try { XmlSerializer serializer = Xml.newSerializer(); File file = new File(getFilesDir(),"backup.xml"); FileOutputStream fos = new FileOutputStream(file); serializer.setOutput(fos, "utf-8"); serializer.startDocument("utf-8", true); serializer.startTag(null, "smss"); for (SmsInfo sms : list) { serializer.startTag(null, "sms"); serializer.startTag(null, "iphone"); serializer.text(sms.getIphone()); serializer.endTag(null, "iphone"); serializer.startTag(null, "mydate"); serializer.text(sms.getMyDate()); serializer.endTag(null, "mydate"); serializer.startTag(null, "body"); serializer.text(sms.getBody()); serializer.endTag(null, "body"); serializer.endTag(null, "sms"); } serializer.endTag(null, "smss"); serializer.endDocument(); fos.close(); } catch (Exception e) { e.printStackTrace(); } }