hi there guys im really struggling with my implemented ChildEvent listener. i have a few activities that i wanted to use the same Listener for. but it wont remove the listener. so when i switch activites it still contains the data passed in by the previous activity. then it passes in the new data underneath this. can some one please explain what im doing wrong.
this is my listener code
public ChildEventListenerHarrop(ListView mlv, Context context){
this.mContext = context;
this.mlv = mlv;
Log.i("Event","Started");
}
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Log.i("Event","Added");
Dl_Strings dlStrings = dataSnapshot.getValue(Dl_Strings.class);
Downloadscount.add(String.valueOf(dlStrings.downloads));
AppNameList.add(dlStrings.appname);
urlList.add(dlStrings.url);
ApkList.add(dlStrings.apkname);
Aboutapp.add(dlStrings.about);
appImage.add(dlStrings.image);
DOWNLOADS.add(dlStrings.tag);
final String[] arr = AppNameList.toArray(new String[AppNameList.size()]);
String[] arr1 = Aboutapp.toArray(new String[Aboutapp.size()]);
String[] arr2 = appImage.toArray(new String[appImage.size()]);
final String[] arr3 = Downloadscount.toArray(new String[Downloadscount.size()]);
apkData = new dataListAdapter(mContext, arr, arr1, arr2, arr3);
mlv.setAdapter(apkData);
apkData.notifyDataSetChanged();
mlv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
tag = DOWNLOADS.get(i).toString();
apkNames = AppNameList.get(i).toString();
DownloadFileFromURL dl = new DownloadFileFromURL(mContext, apkNames, mCurrentPhotoPath);
dl.execute(urlList.get(i));
Count_System count = new Count_System(mrootRef);
count.count();
App_DownLoadCounter(tag);
}
});
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Log.i("Event","Changed");
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
Log.i("Event","Deleted");
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
Log.i("Event","Moved");
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.i("Event","Canceled");
}
its passed in to my baseAdapter
public class dataListAdapter extends BaseAdapter { String[] Title, Detail, Counter;
String[] image;
Context mContext;
public dataListAdapter() {
Title = null;
Detail = null;
image = null;
Counter = null;
}
public dataListAdapter(Context c, String[] text, String[] text1, String[] imge, String[] counter) {
Title = text;
Detail = text1;
image = imge;
Counter = counter;
this.mContext = c;
}
public int getCount() {
// TODO Auto-generated method stub
return Title.length;
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final View row;
if (convertView == null) {
row = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom, parent, false);
} else {
row = convertView;
}
final TextView title, detail, dlcounter;
title = (TextView) row.findViewById(R.id.titleapp);
detail = (TextView) row.findViewById(R.id.detail);
dlcounter = (TextView) row.findViewById(R.id.counterdl);
ImageView img = (ImageView) row.findViewById(R.id.img);
title.setText(Title[position]);
detail.setText(Detail[position]);
Glide.with(mContext).load(image[position]).into(img);
dlcounter.setText(Counter[position]);
return (row);
}
then finally called in my activities using onStart and onStop as the listener create point and end point?
ChildEventListenerHarrop listenerHarrop;
private void AddListener(){
listenerHarrop = new ChildEventListenerHarrop(mlv,Animeapps.this);
ref.addChildEventListener(listenerHarrop);
listener = listenerHarrop;
}
private void RemoveListener(){
ref.removeEventListener(listener);
ref = null;
listener = null;
mrootRef = null;
finish();
}
@Override
protected void onStart() {//Ive tried moving this below the super in both this and onStop
AddListener();
super.onStart();
Log.i(Apptype + " Listener","Added");
}
@Override
protected void onStop() {
// Tried these in OnCreate and on Destroy
RemoveListener();
super.onStop();
// these logs are called but listener is still not removing?
Log.i(Apptype + " Listener","Removed");
}
}