public class Student implements Serializable {
private int id;
private String name;
private float avg;
public Student(int id, String name, float avg) {
this.id = id;
this.name = name;
this.avg = avg;
}
}
Button intentButton = findViewById(R.id.intentButton);
intentButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
intent.putExtra("student",new Student(120151559,"Ramy Helow",99));
startActivity(intent);
}
});
Bundle bundle = getIntent().getExtras();
if(bundle!=null){
Student s = (Student) bundle.getSerializable("student");
TextView textView = findViewById(R.id.textView);
textView.setText("ID: "+s.getId()+"\nName: "+s.getName()+"\nAverage: "+s.getAvg());
}