What is the best way to pass data from an Activity to fragment, but the fragment is hosted by another activity.
Elaborating: Activity A hosts Fragment A (content in activity A) <== Activity B
I have already achieved this, but apparently, my way of doing it has caused some memory leak.
An example would be to refresh a RecyclerView contained in a fragment when an activity is closed, but I do not want to put it in the onResume
.
interface contained in the activity(is not the host)
public class Activity extends AppCompatActivity{
public static OnlistenClose delegate;
public interface OnlistenClose {
void refreshList();
}
}
//fragment that implements the interface
public class FragmentB extends Fragment implements Activity.OnlistenClose{
Activity.delegate = this;
@Override
public void refreshList(){
//my code
}
}
Using square/leakcanary indicates there are leaks.