Try calling getArray (). add (et.getText (). toString ()); and notifyArray (); inside onResume () MainActivity and NOT from AddStudentActivity (not recommended!)
So, onResume (), you would ideally want to add a new student to the list, so in your case you can get the student’s name using a common common object such as a hash table or something similar, make it single, and use this from anywhere in the application
A general class might look something like this:
class CommonHashtable{ private static Hashtable<String, Object> commonHashtable = null; public static getInstance(){ if(commonHashtable == null) commonHashtable = new Hashtable<String, Object>(); return commonHashtable; }
on getInstance (), it returns a commonHashtable that can be used to temporarily store values!
so add this to the clickbutton click event
Hashtable hash = CommonHashtable.getInstance(); hash.put("NEW_STUDENT_NAME", et.getText().toString());
and add this to you onResume () from MainActivity
Hashtable hash = CommonHashtable.getInstance(); Object studentName = (String) hash.get("NEW_STUDENT_NAME"); if(studentName != null){ notifyArray(); }
source share