1

I am creating an android app for jokes. I have multiple jokes which i want to share with whatsapp users.

Do i need write share intent individually for each jokes?

For Example:

public void share(View view) 
    {
        Intent sendIntent = new Intent();
           sendIntent.setAction(Intent.ACTION_SEND);
           sendIntent.putExtra(Intent.EXTRA_TEXT,
               "Q: What did the butcher say when he backed into the meat-grinder?
A: Looks like I'm getting a little behind in my work!");
           sendIntent.setType("text/plain");
           startActivity(sendIntent);
    }

please help.

A2zbollywood
  • 35
  • 1
  • 8

1 Answers1

0

To make it easier to understand, just think that Intent is a courier, that help you delivery data from Activity1 to Activity2.

In this case, you can try a simple way: put your joke inside a string:

String joke = "Q: What did the butcher say when he backed into the meat-grinder?\n A: Looks like I'm getting a little behind in my work!";

sendIntent.putExtra(Intent.EXTRA_TEXT,joke);

Enjoy trying other way, when you improve your Java

Jacky
  • 2,924
  • 3
  • 22
  • 34
  • Thank u very much Jacky. now the concept is clear. but do i have to write intents individually for each jokes? – A2zbollywood Mar 18 '15 at 11:37
  • no, instead, you can start trying by writing each joke with each string. Example: String joke1 = ....; String joke2 = .... ; and "putExtra" those variable to intent. joke1, joke2 ... is the 'packet', inside the 'truck' Intent, that being delivered. – Jacky Mar 18 '15 at 15:18
  • As u know I'm new to android development.. Will u please give me an example with complete code. Thanks once again for all your help. Highly appreciated! – A2zbollywood Mar 18 '15 at 21:26
  • Take a look at this sample: http://www.codeshare.io/lFtuQ If you are willing to see real code, and i'm assume that you know how to rebuild from other's code, i will send you entire code – Jacky Mar 19 '15 at 02:26
  • hi jacky...i'm using in fragment... plz have a look at this code http://www.codeshare.io/D3DiH ...it's giving me the error for getInent() & i changed to this also Intent sendIntent = new Intent(getActivity(), JokeActivity.class); because it was giving me the error. and please also tell me how my xml file will look like main.xml & jokes.xml. sorry for bothering you. Thanks once again. – A2zbollywood Mar 19 '15 at 06:47
  • It seems that it's hard to explain in just few words :), just give me your codes (may be zip file) and tell me what do you want, i will try modify it. Hope can give you one good example – Jacky Mar 19 '15 at 09:51