0

the code goes similary like this :

So i got a button that opens a new intent and there is a code to randomly chose a diferent case .like

case1: system.out.println("a"); break; case2: system.out.println("b"); break;

so the code choses one , but my problem is i want that text to be sent to a new intent and be displey as a text in a new intent , any ideas ?

Ajsi
  • 1

5 Answers5

0

you need to create new intent within each case and pass your text value as string object in intent.putExtra() method

Intent intent = new Intent(context,youractivity.class);  
intent.putExtra("deal", yourstingobject);
karan
  • 8,637
  • 3
  • 41
  • 78
0

What I can get from your question is that you want to send a string to activity and set the string to textview in the activity

        case 1:
               Intent i=new Intent(this,Other.class);
               i.putExtra("key", "Any String");
               startActivity(i);

In Other Class

       String value=getIntent().getStringExtra("key");
       now set the string in textview
Rohit
  • 191
  • 2
  • 9
0

Add your text in an Intent.

Intent intent = new Intent(getApplicationContext(),
   MySecondClass.class);

   intent.putExtra("name", name);
   startActivity(intent);

Get value from an intent in MySecondClass.java

 Intent intent =  getIntent();

 String name    =  intent.getStringExtra("name");
Anirban Pal
  • 529
  • 4
  • 10
  • Check this link for example with full source code http://www.javasrilankansupport.com/2012/06/send-data-to-another-activity-simple.html – Anirban Pal Aug 30 '14 at 13:01
0

this is code:

Intent intent = new Intent(thisActivity,secondActivity.class);
intent.putExtra("extraText", "number");
startActivity(intent);

and in the second activity:

Long number=getIntent().getExtras().getLong("extraText");
saleh sereshki
  • 2,402
  • 3
  • 17
  • 18
0

//SenderActivity

Intent intent=new Intent(SenderActivity.this,ReceiverActivity.class);
intent.putExtra("yourKey",anystring);
startActivity(intent);

//ReceiverActivity:

String senderMessage= getIntent().getExtras().getString(("yourKey")).toString();
Haedrian
  • 4,240
  • 2
  • 32
  • 53
ferandro
  • 3
  • 3