snippetjavaMinor
How can I speed up my RSS feed Android App?
Viewed 0 times
canrssandroidappfeedhowspeed
Problem
I have a problem with parsing RSS from a PHP page because the app is too slow.
This is my parsing code:
```
public void getdataparse(String url) {
Log.d("Do in Background","Start Call Void");
String dbtitle = "";
String dbDesc = "";
String dbimgicon = "";
String dbimg = "";
String dblink = "";
String dbpubdate = "";
String dborderStg = "";
String dbsourcename = "";
String dbimagecheck = "";
int dbfff = 0;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new URL(url).openStream());
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("item");
for (int temp = 0; temp < nList.getLength(); temp++) {
dbtitle = "";
dbDesc = "";
dbimgicon = "";
dbimg = "";
dblink = "";
dbpubdate = "";
dborderStg = "";
dbsourcename = "";
dbimagecheck = "";
dbfff = 0;
Datemx = 0;
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
dbtitle = getTagValue("title", eElement);
dbDesc = getTagValue("description", eElement);
String[] timeformated = new String[2];
timeformated = gettime(getTagValue("pubdate", eElement));
dbpubdate = timeformated[0];
dborderStg = timeformated[1];
Log.d("pubDate = ", "" + dbpubdate + "OrderStg = " + dborderStg);
dblink = getTagValue("link", eElement);
dbimgicon = getTagValue("sicon", eElement);
dbimg = "http://s14.postimg.or
This is my parsing code:
```
public void getdataparse(String url) {
Log.d("Do in Background","Start Call Void");
String dbtitle = "";
String dbDesc = "";
String dbimgicon = "";
String dbimg = "";
String dblink = "";
String dbpubdate = "";
String dborderStg = "";
String dbsourcename = "";
String dbimagecheck = "";
int dbfff = 0;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new URL(url).openStream());
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("item");
for (int temp = 0; temp < nList.getLength(); temp++) {
dbtitle = "";
dbDesc = "";
dbimgicon = "";
dbimg = "";
dblink = "";
dbpubdate = "";
dborderStg = "";
dbsourcename = "";
dbimagecheck = "";
dbfff = 0;
Datemx = 0;
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
dbtitle = getTagValue("title", eElement);
dbDesc = getTagValue("description", eElement);
String[] timeformated = new String[2];
timeformated = gettime(getTagValue("pubdate", eElement));
dbpubdate = timeformated[0];
dborderStg = timeformated[1];
Log.d("pubDate = ", "" + dbpubdate + "OrderStg = " + dborderStg);
dblink = getTagValue("link", eElement);
dbimgicon = getTagValue("sicon", eElement);
dbimg = "http://s14.postimg.or
Solution
none of those Variables need to be set to
This can be set early and outside of the if block and the for loop:
Otherwise it is a Magic string that you will have to search for later.
The
otherwise you are creating this variable and assigning a lot of data to it and never using it every time you go through the loop.
"" inside the for loop, they have already been set.This can be set early and outside of the if block and the for loop:
dbimg = "http://s14.postimg.org/cs10sq11d/whitemega.png";Otherwise it is a Magic string that you will have to search for later.
The
id isn't doing anything here, I don't think that you need it at all, you should be able to call the code like thishandler.insertrssfeedData(dbtitle, dbDesc, dbimg, dbimgicon, dblink, dbpubdate, dbfff, dbsourcename , dbimagecheck);otherwise you are creating this variable and assigning a lot of data to it and never using it every time you go through the loop.
Code Snippets
dbimg = "http://s14.postimg.org/cs10sq11d/whitemega.png";handler.insertrssfeedData(dbtitle, dbDesc, dbimg, dbimgicon, dblink, dbpubdate, dbfff, dbsourcename , dbimagecheck);Context
StackExchange Code Review Q#52008, answer score: 5
Revisions (0)
No revisions yet.