在我的android项目中,我正在阅读一个由一个python脚本持续更新的xml文件。对于更新数据,我一直在读xml文件,每当python脚本用xml文件更新数据时,我就在我的应用程序中使用它。在
但现在的问题是,由于python脚本和我的android项目连续访问一个xml文件(一个资源,所以我认为是并发问题),所以从xml文件中获取数据并通过python脚本将数据写入xml文件需要很长时间。在
那么,python脚本和android应用程序之间有没有简单的通信方式,这样我就可以避免使用xml文件,直接使用python脚本发送给我的数据?
而且它能让我更快的执行。在
我试过了,(这是我用来访问xml文件的android代码)public void getData() throws Exception {
try
{
while(!isStop)
{
isStop=parseXmlData();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
private boolean parseXmlFile(){
//get the factory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
boolean flag=false;
try {
//Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
//parse using builder to get DOM representation of the XML file
File file=new File("/mnt/sdcard/xmldata.xml");
FileInputStream fin=null;
if(file.isFile())
{
try
{
fin=new FileInputStream(file);
}catch(Exception e)
{
}
}
dom = db.parse(fin);
flag = parseDocument();
// from this I am getting last xml value "stop" then it returns
true and from while loop I am exited..
}catch(ParserConfigurationException pce) {
//pce.printStackTrace();
}catch(SAXException se) {
//se.printStackTrace();
}catch(IOException ioe) {
//ioe.printStackTrace();
}
return flag;
}
编辑:在我看来,我有三个选择使用管道
套接字通信
艾德尔
那么哪一个更好?为什么?在
如果我做错了,请引导我。谢谢