0

I would like to use a ShareActionProvider to share the contents of my ListFragment (which consists of text entries from an ArrayAdapter fed with a ArrayList<MyObject>).

How do I do this?

I know that I will have to create a new Intent and to use setType("text/plain") but for setAction() should I use Intent.ACTION_SEND and Intent.ACTION_SEND_MULTIPLE?

When setting the content, should I use putExtra or putParcelableArrayListExtra?

Do I set the Intent with the data from the ListFragment, or from the ArrayAdapter, or from the ArrayList<MyObject> that is fed into ArrayAdapter, or from the data before the ArrayList were constructed?

Fred
  • 12,086
  • 7
  • 60
  • 83

1 Answers1

0

for setAction() should I use Intent.ACTION_SEND and Intent.ACTION_SEND_MULTIPLE?

That is your choice to make, as the author of the app. If you are expecting to share one piece of text (that you assembled from many pieces yourself), use ACTION_SEND. If you are expecting to share many pieces of text, use ACTION_SEND_MULTIPLE.

Note that I would expect about a 100:1 ratio of apps supporting ACTION_SEND compared to ACTION_SEND_MULTIPLE. So, if your objective is for this sharing to be generally useful, you would want to steer towards ACTION_SEND.

More importantly, you need to determine what the users are going to want to do. Presumably, the point behind your development is for 1+ humans to use this app. If the user of the app is expecting to send one email, or post one tweet, or upload one note based on this data, you should be using ACTION_SEND. If, instead, the user will be expecting to send N messages (or whatever), then that would be something to try with ACTION_SEND_MULTIPLE.

When setting the content, should I use putExtra or putParcelableArrayListExtra?

For ACTION_SEND, it would be putExtra(), passing in the String. For ACTION_SEND_MULTIPLE, it would be putStringArrayListExtra().

Do I set the Intent with the data from the ListFragment, or from the ArrayAdapter, or from the ArrayList that is fed into ArrayAdapter, or from the data before the ArrayList were constructed?

You use a String or ArrayList<String> as noted above. Where you get those values from is your business logic that you as a developer need to decide.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • But my `ArrayAdapter` gets populated by an `ArrayList`, not an ArrayList`. Even so, I can't use `ArrayList` on a `ACTION_SEND`? Am I supposed to loop through the ArrayList with a for loop and build a `StringBuilder` that I feed to `putExtra`? – Fred Feb 16 '14 at 14:23
  • The `ListFragment` is a list that contains *multiple* text entries. I want to send the whole list (consisting of *multiple* text entries). Should I use `ACTION_SEND` or `ACTION_SEND_MULTIPLE`? – Fred Feb 16 '14 at 14:25
  • @Fred: You claim that you are trying to send `text/plain`. *You* need to assemble the `String`(s) to send, because *you* are the only one who knows what those `String`(s) are supposed to look like. "Should I use ACTION_SEND or ACTION_SEND_MULTIPLE?" -- please re-read the first three paragraphs of my answer. Your MIME type is `text/plain`. Whether you are sending one `String` or N `Strings` is dependent upon your business rules. – CommonsWare Feb 16 '14 at 14:30