You can try to use a global variable by extending the Application class, and so you will reference your ChildEventListner, and if you have multiple Listners, you can always use a map or something like this, and when you exit your application, if the list that you are looking for in a null value, set it again or uninstall and install a new Listner (to avoid multiple lists for the same database link).
here is an example:
public class MApplication extends Application { private static Map<String,ChildEventListener> mapListners = new HashMap<>(); public static ChildEventListener getChildEventListener(String key) { if (mapListners.containsKey(key)) return mapListners.get(key); else return null; } public static void setChildEventListener(ChildEventListener eventListener,String key) { mapListners.put(key,eventListener); } }
and add this to your Manifest.xml file
<application android:name=".MApplication" android:icon="@drawable/icon" android:label="@string/app_name">
source share