3

I have an IntentService that goes connects to a website and creates a list with parsed HTML via JSoup. I now need to pass that list back in a Bundle and I'm not sure how to do it. Here is my code for the IntentService:

public class NewerService extends IntentService {

public NewerService() {
    super("NewerService");
    // TODO Auto-generated constructor stub
}

@Override
protected void onHandleIntent(Intent intent) {
    ResultReceiver rec = intent.getParcelableExtra("receiverTag");
    String playersName = intent.getStringExtra("Player");
    List<String> list = new ArrayList<String>();
    Document doc = null;
    try {
        doc = Jsoup.connect("http://espn.go.com/nhl/team/stats/_/name/phi/philadelphia-flyers").get();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    for (Element table : doc.select("table.tablehead")) {
        for (Element row : table.select("tr")) {
            Elements tds = row.select("td");
            if (tds.size() > 6) {
                String a = tds.get(0).text() + ":" + " Games Played: "+
                    tds.get(1).text()+"," + " GOALS: " + tds.get(2).text()+"," + 
                    " ASSISTS: " + tds.get(3).text() + " POINTS: " + 
                    tds.get(4).text() + " PLUS/MINUS: " + tds.get(5).text() + " 
                    PIM: " + tds.get(6).text();

                    list.add(a); // Add the string to the list
             }

        }
    }   
}

I appreciate any help in advance. Thank you

Cat
  • 66,919
  • 24
  • 133
  • 141
MaxK
  • 437
  • 5
  • 8
  • 20
  • Check this link, "http://stackoverflow.com/questions/6543811/intent-putextra-list" It solved my problem! – RStar Jul 31 '14 at 12:47

1 Answers1

15

Have you tried using Bundle.putStringArrayList or Intent.putStringArrayListExtra?

If you mean you don't know how to start an activity from a service, try this question.

Community
  • 1
  • 1
Geobits
  • 22,218
  • 6
  • 59
  • 103
  • No this works. I start the service from the activity...the service grabs the list then I do what you suggested and put the list in the bundle with putStringArrayList and sent the bundle back to the activity. Thanks – MaxK Feb 19 '13 at 23:53