Android Run class on new thread -


this question has answer here:

i trying parse .pls file urls play. used following code, giving networkonmainthread exception. never did threaded apps before; how can run class on new thread?

public class getstreamingurl { private static string logtag = "getstreamingurl"; private context mcontext; public string url1; public linkedlist<string> url2;   public getstreamingurl(context context) { log.i(logtag, "call constructor"); this.mcontext = context;  }  public linkedlist<string>  getstreamingurl(string url) {  log.i(logtag, "get streaming url"); final bufferedreader br; string murl = null; linkedlist<string> murls = null; try {     urlconnection murl = new url(url).openconnection();     br = new bufferedreader(             new inputstreamreader(murl.getinputstream()));     murls = new linkedlist<string>();     while (true) {         try {             string line = br.readline();              if (line == null) {                 break;             }             murl = parseline(line);             if (murl != null && !murl.equals("")) {                 murls.add(murl);              }         } catch (ioexception e) {             e.printstacktrace();         }     } } catch (malformedurlexception e) {     // todo auto-generated catch block     e.printstacktrace(); } catch (ioexception e) {     // todo auto-generated catch block     e.printstacktrace(); } log.i(logtag, "url stream :" + murl); return murls; }  private string parseline(string line) { if (line == null) {     return null; } string trimmed = line.trim(); if (trimmed.indexof("http") >= 0) {     return trimmed.substring(trimmed.indexof("http")); } return "";     }    } 

i trying parse .pls file urls play. used following code, giving networkonmainthread exception. never did threaded apps before; how can run class on new thread?

just this:

new thread(new runnable() {              @override             public void run() {                 // stuffs here              }         }).start(); 

hope helps.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -