title: how to retrive data from getters in another activity in android
body: <p>I am creating an android app in which I store in firebase and show a list with subitems in one activity and access that list in another activity by clicking a button. I have stored and showed the data in firebase and in my first activity, but I can't fetch that list in the other activity.
   My code:-</p>
  
  <p>Main Activity:-</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  EditText getName, getNum;
  Button btn,btnNext;
  TextView textView;
  ListView listView;
  DatabaseReference fb;
  List&lt;Contact&gt; contactList = new ArrayList&lt;&gt;();
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      getName = findViewById(R.id.ed1);
      getNum = findViewById(R.id.ed2);
      textView = findViewById(R.id.text);
      btn = findViewById(R.id.btn);
      btnNext = findViewById(R.id.btnNext);
  
      listView = findViewById(R.id.listView);
  
      fb = FirebaseDatabase.getInstance().getReference("Contacts");
  
      btnNext.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent intent = new Intent(MainActivity.this,Main2Activity.class);
              startActivity(intent);
              finish();
          }
      });
  
      btn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              addContacts();
          }
      });
  
      fb.addChildEventListener(new ChildEventListener() {
          @Override
          public void onChildAdded(DataSnapshot dataSnapshot, String s) {
              Contact contact = dataSnapshot.getValue(Contact.class);
              contactList.add(contact);
              listadapter list = new listadapter(MainActivity.this,contactList);
              listView.setAdapter(list);
          }
  
          @Override
          public void onChildChanged(DataSnapshot dataSnapshot, String s) {
              notify();
          }
  
          @Override
          public void onChildRemoved(DataSnapshot dataSnapshot) {
  
          }
  
          @Override
          public void onChildMoved(DataSnapshot dataSnapshot, String s) {
  
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  
  }
  
  public void addContacts() {
      String name = getName.getText().toString();
      String num = getNum.getText().toString();
      String id = fb.push().getKey();
      Contact contact = new Contact(name,num);
      fb.child(id).setValue(contact);
  }
  }
  </code></pre>
  
  <p>Contact getters class</p>
  
  <pre><code>   public class Contact {
  
     String contact;
     String name;
  
  public Contact() {  }
  
  public Contact(String name, String contact) {
      this.name = name;
      this.contact = contact;
  }
  
  public String getName() {
      return name;
  }
  
  public String getContact() {
      return contact;
  }
  }
  </code></pre>
  
  <p>custom adapter class</p>
  
  <pre><code>public class listadapter extends ArrayAdapter&lt;Contact&gt; {
  
  private Activity context;
  private List&lt;Contact&gt; contactList;
  
  public listadapter(Activity context, List&lt;Contact&gt; contactList) {
      super(context,R.layout.list,contactList);
  
      this.context = context;
      this.contactList = contactList;
  }
  
  public View getView(int position, @Nullable View convertView, @NonNull   ViewGroup parent) {
      LayoutInflater inflater = context.getLayoutInflater();
  
      View listViewItem = inflater.inflate(R.layout.list, null, true);
  
      TextView textViewName = listViewItem.findViewById(R.id.name);
      TextView textViewContact = listViewItem.findViewById(R.id.num);
  
      Contact contact = contactList.get(position);
  
  
      textViewName.setText(contact.getName());
      textViewContact.setText(contact.getContact());
  
      return listViewItem;
  }
  }
  </code></pre>
  
  <p>Activity in which i'm trying to fetch</p>
  
  <pre><code>public class Main2Activity extends AppCompatActivity {
  Button getSub;
  List&lt;Contact&gt; list = new ArrayList&lt;&gt;();
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main2);
  
      getSub = findViewById(R.id.getSub);
  
      getSub.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              Toast.makeText(getApplicationContext(),"Num : "+list.get(0).getContact(),Toast.LENGTH_LONG).show();
          }
      });
  }
  }
  </code></pre>
  
  <p>Solution:- I fetched the list directly from firebase and it works</p>
  
  <pre><code>        protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main2);
          call = findViewById(R.id.call);
  
         db = FirebaseDatabase.getInstance().getReference("Trusted contacts");
  
      Handler handler = new Handler();
      handler.postDelayed(new Runnable() {
      @Override
          public void run() {
              msgAll();
              for(int i=0;i&lt;ex.size();i++) {
                  getNum = "tel: "+ex.get(i).getmText2();
                  callAll(getNum);
  
              }
  
          }
      }, 500);
  }
         @Override
         protected void onStart() {
         super.onStart();
      db.addChildEventListener(new ChildEventListener() {
          @Override
          public void onChildAdded(DataSnapshot dataSnapshot, String s) {
              ExampleItem contact = dataSnapshot.getValue(ExampleItem.class);
              ex.add(contact);
          }
  
          @Override
          public void onChildChanged(DataSnapshot dataSnapshot, String s) {
  
          }
  
          @Override
          public void onChildRemoved(DataSnapshot dataSnapshot) {
  
          }
  
          @Override
          public void onChildMoved(DataSnapshot dataSnapshot, String s) {
  
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  
  }
  </code></pre>