1

I want to pass my arraylist via implicit intent just because I want to send my data in listview via whatsapp. Here is my code

public void save()
{

   ArrayList<String> arrayList= new ArrayList<String>(Arrays.asList(combination));


    Intent intent= new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");

    intent.putStringArrayListExtra(Intent.EXTRA_TEXT,arrayList);

    startActivity(intent);
}

save() is a method that gets called when user presses SHARE button. But it actually doesn't pass anything to whatsapp.

Diligent Key Presser
  • 4,183
  • 4
  • 26
  • 34

1 Answers1

2

Concatenate your strings together into one single string. Then, use that as your EXTRA_TEXT value. No application will be expecting an ArrayList<String> as the EXTRA_TEXT value, and so your existing code will not work.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • @DhoniSingh: http://stackoverflow.com/questions/599161/best-way-to-convert-an-arraylist-to-a-string – CommonsWare May 07 '16 at 17:35
  • String string= Arrays.toString(arrayList); and then intent.putExtra(Intent.EXTRA_TEXT,string); . This is what I have already tried . It works but give you a single line ...I want the actual list , not a line – Dhoni Singh May 07 '16 at 17:37
  • @DhoniSingh: Well, the accepted answer on the question that I linked to shows joining them as separated by tabs. You are welcome to use `\n` instead of `\t` to join them by newlines. Since this is Android, you are also welcome to [use `TextUtils.join('\n', arrayList)`](http://developer.android.com/reference/android/text/TextUtils.html#join%28java.lang.CharSequence,%20java.lang.Iterable%29), if you prefer. Expecting WhatsApp to do that work for you, though, is unrealistic. – CommonsWare May 07 '16 at 17:40