0

I am working through an app in Android Studio that passes data using intent for school. I have created my object to pass the data through and started the Intent but I keep getting a warning that my putExtra method cannot be resolved. Any ideas? Thanks in advance.

public class MainActivity extends AppCompatActivity {

private ContactInfo contactobject;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Bundle extra = getIntent().getExtras();
    contactobject = (ContactInfo)extra.get("contact");
    if (contactobject == null )
        contactobject = new ContactInfo();

    TextView name1 = (TextView) findViewById(R.id.Name1);
    name1.setText(contactobject.getOneName());

    TextView phone1 = (TextView) findViewById(R.id.Phone1);
    phone1.setText(contactobject.getOnePhone());

    TextView email1 = (TextView) findViewById(R.id.Email1);
    email1.setText(contactobject.getOneEmail());

    TextView kin1 = (TextView) findViewById(R.id.Kin1);
    kin1.setText(contactobject.getOneKin());

    TextView name2 = (TextView) findViewById(R.id.Name2);
    name2.setText(contactobject.getTwoName());

    TextView phone2 = (TextView) findViewById(R.id.Phone2);
    phone2.setText(contactobject.getTwoPhone());

    TextView email2 = (TextView) findViewById(R.id.Email2);
    email2.setText(contactobject.getTwoEmail());

    TextView kin2 = (TextView) findViewById(R.id.Kin2);
    kin2.setText(contactobject.getTwoEmail());

}


public void EditPrimary(View view)
{
    Intent intent1 = new Intent(getApplicationContext(), Edit1.class);
    Intent intent = intent1.putExtra("contact", contactobject);
    startActivity(intent1);
}

}
Ajeet Choudhary
  • 1,969
  • 1
  • 17
  • 41
Trigger
  • 21
  • 1
  • 1
  • 3
  • public void EditPrimary(View view) { Intent intent1 = new Intent(getApplicationContext(), intent1.putExtra("contact", contactobject); startActivity(intent1); } – akhilesh0707 Jul 09 '17 at 03:40

3 Answers3

3

There are two points:

Point 1: don't need to assign intent1.putExtra("contact", contactobject); value to other variable

Point 2: Your ContactInfo Class must implements class Parcelable or Serializable while you are passing it through an Intent.

See this post to learn how to make a Class Parcelable.

I am sure you are missing second point.

Ajeet Choudhary
  • 1,969
  • 1
  • 17
  • 41
  • 1
    Thanks I made ContactInfo Parcelable and it likes that. This is the first time I have ran into this so I will need to dig into how that works a little more. – Trigger Jul 09 '17 at 12:53
  • see these links, may help you..https://www.survivingwithandroid.com/2015/05/android-parcelable-tutorial-list-class-2.html, http://www.vogella.com/tutorials/AndroidParcelable/article.html – Ajeet Choudhary Jul 09 '17 at 13:31
0

You can't assign the putExtra call to a new intent variable:

public void EditPrimary(View view)
{
    Intent intent1 = new Intent(getApplicationContext(), Edit1.class);
    intent1.putExtra("contact", contactobject);
    startActivity(intent1);
}
M0CH1R0N
  • 756
  • 9
  • 19
0
int Number;
etNumber = (EditText)findViewById(R.id.etNumber);
Number = Integer.parseInt(etNumber.getText().toString());
Intent i = new Intent(getApplicationContext(),Result.class);
Bundle bundle = new Bundle();
bundle.putInt("Number",Number);
i.putExtras(bundle);
startActivity(i);
Ravina
  • 1
  • 1
  • 1
    Code only answers aren't useful for the community. Please look at [How to Answer](http://stackoverflow.com/questions/how-to-answer) – abpatil Oct 17 '17 at 06:23