0

I already have a program that carries text from class to another but I want to make a program that can carry text from one class to another.

            String l1 = ing1.getText().toString();
            String a = ing2.getText().toString();
            String b = ing3.getText().toString();
            String c = ing4.getText().toString();
            String d = ing5.getText().toString();
            String e = ing6.getText().toString();

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

            intent.putExtra("A", l1);
            intent.putExtra("B", a);
            intent.putExtra("C", b);
            intent.putExtra("D", c);
            intent.putExtra("E", d);
            intent.putExtra("F", e);

            startActivity(intent);

            //PART2 (INTENTS)

            String title1 = title.getText().toString();
            String s1 = step1.getText().toString();
            String s2 = step1.getText().toString();
            String s3 = step1.getText().toString();
            String s4 = step1.getText().toString();
            String s5 = step1.getText().toString();
            String s6 = step1.getText().toString();
            String s7 = step1.getText().toString();
            String s8 = step1.getText().toString();

            // create a new intent
            Intent i = new Intent(getApplicationContext(), classB.class);
            // put the name and phone(to be sent to other activity) in intent
            i.putExtra("TITLE", title);
            i.putExtra("STEP1", s1);
            i.putExtra("STEP2", s2);
            i.putExtra("STEP3", s3);
            i.putExtra("STEP4", s4);
            i.putExtra("STEP5", s5);
            i.putExtra("STEP6", s6);
            i.putExtra("STEP7", s7);

I want to be able to carry the first intent to class a and when a button in class a is pressed I want it to go to class b and to carry the intent. Can this be done?

Tanner
  • 22,205
  • 9
  • 65
  • 83

2 Answers2

0

i want to be able to carry the first intent to class a and when a button in class a is presses to go to class b and to carry the intent.

I have no idea what that means but if you mean that you want to send the Intent to Activity B when a button is pressed, you will first have to implement a listener for your button.

mBtn.setOnClickListener(new View.onClickListener(){
  public void onClick(View v){
     Intent activityB = new Intent(ActivityA.this,ActivityB.class);
     activityB.putExtra("key",value);
     startActivity(activityB);
  }
});  

Now in Activity B you can do something like:

@Override
public void onResume(){
  super.onResume();
  Intent intentFromA = getIntent();
  Bundle dataFromA = intentFromA.getExtras();
}
An SO User
  • 24,612
  • 35
  • 133
  • 221
0

This can definitely be done.

In the class where you receive the first intent (class A), grab the intent sent to this clas:

Bundle extras = getIntent().getExtras();
 if (extras != null) {
  String data= extras.getString("EXTRA");
   if (datas!= null) {
    intentToClassB.putExtra("EXTRA", data);
   }  
 }

where intentToClassB should be the globally defined intent that will take you to Class B.

Essentially, you grab the intent sent from the last activity and immediately connect it to the intent that will head to class B. NOTE: This code should go in your onCreate() method

krodmannix
  • 845
  • 10
  • 30