これは、OnCreateメソッドのValueEventListenerです。私はこれがOnDestroyメソッドを破壊しようとしています。なぜなら、メモリリークを引き起こしている可能性があり、そうすることも良い習慣であると読んだからです。OnDestroy(Android Firebase)でこのリスナーを削除するにはどうすればよいですか?
mDatabase.child(mPost_key).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
display_author = (String) dataSnapshot.child("author").getValue();
display_quote = (String) dataSnapshot.child("quote").getValue();
display_pic_url = (String) dataSnapshot.child("pic_url").getValue();
categoryData=(String) dataSnapshot.child("catg").getValue();
display_prof=(String) dataSnapshot.child("prof").getValue();
copyQuote = (display_quote + " - " +display_author);
try {
author.setText(display_author);
quote.setText(display_quote);
category.setText(categoryData);
profession.setText(display_prof);
Glide.with(SingleExploreQuotes.this).load(display_pic_url).override(192, 192).into(profile_img);
} catch (Exception e) {
finish();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
「Expression Expected」と言って、ValueEventListenerにエラーが表示されます。 –