1

I have 2 class one is login_class second is student_class which is showing details of student.

What i have to do is when i login. In response i get the students details like student_name,student_srno,student_father_name,student_mother_name etc.

This is my bean(Getter Setter) class

    package com.smartschoolapp;

public class Bean {

String username, password, srno, studentname, classname, sec, contact,
father_name, mother_name, dob;



public  Bean(String username,String password,String srno,String studentname,String classname,String sec,String contact,String father_name,String mother_name,String dob) {
    this.username=username;
    this.password= password;
    this.srno=srno;
    this.studentname=studentname;
    this.classname=classname;
    this.sec=sec;
    this.contact=contact;
    this.father_name=father_name;
    this.mother_name=mother_name;
    this.dob =dob;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getSrno() {
    return srno;
}

public void setSrno(String srno) {
    this.srno = srno;
}

public String getStudentname() {
    return studentname;
}

public void setStudentname(String studentname) {
    this.studentname = studentname;
}

public String getClassname() {
    return classname;
}

public void setClassname(String classname) {
    this.classname = classname;
}

public String getSec() {
    return sec;
}

public void setSec(String sec) {
    this.sec = sec;
}

public String getContact() {
    return contact;
}

public void setContact(String contact) {
    this.contact = contact;
}

public String getFather_name() {
    return father_name;
}

public void setFather_name(String father_name) {
    this.father_name = father_name;
}

public String getMother_name() {
    return mother_name;
}

public void setMother_name(String mother_name) {
    this.mother_name = mother_name;
}

public String getDob() {
    return dob;
}

public void setDob(String dob) {
    this.dob = dob;
}

public Bean() {

}
}

And this is my login_class where i add data of the student in list.

   class login_class extends activity{  
 Bean beanobj;
 List student_detail_list;
 .....
   {
        String name = getting data from response;
        ......... so on

          beanobj = new Bean();
        beanobj.studentname(name);
        beanobj.student_parent_name(parentname);
        .............so on

        }

        order_list.add(beanobj); // the details to list
        }

Now the next activity student_class where i want to show the student in listview

public class student_class extends Activity {
ListView student_listview;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.student_list);


    student_listview = (ListView) findViewById(R.id.student_listview);



   }
    }

*==>> in login_class i have created List student_detail_list how can i get it in my student_class class and retrieve data . Thanks

2 Answers2

0

Realize the "class Bean implements Parcelable". When go to "student_class" from "login_class", just put the "student bean data" inside the Intent. After going to student_class, you can get the "student bean data" from the intent, here the sample code:

Intent intent = new Intent(login_class.this, student_class.class)
intent.putParcelableArrayListExtra("content", student_detail_list);
startActivity(intent);

In "student_class":

student_detail_list = getIntent().getParcelableArrayListExtra("content");
moon
  • 136
  • 6
0

There are a lot a ways to do that.

1.Recommended Solution : How to pass an object from one activity to another on Android
you can serialize your objects and put it into the intent. This is the recommended solution but there are some problems here. If your data contains a lot of memory, it might crash your application in runtime.

2. You can save your array into the file, send file path to other activity as with URL. In the second activity read the file and create the array in second activity as well.

3. My favourite solution is create a singleton class for student array, reach the class in any activity you want. But you should be careful because singleton pattern has some issues by design also it will stay in memory all the time

Community
  • 1
  • 1
Abdullah Tellioglu
  • 1,434
  • 1
  • 10
  • 26