I call a method in an activity when I am on one of the fragments and then return result of method in activity on the same fragment I am in but surprisingly is gives me error saying fragment is not added yet. I print isAttached and isDetached method values and its true and false respectively. Also getContext returns null. How is this possible ?
Before calling the method these method calls return expected values.
Fragment.class
public class myFragment extends Fragment{
@Override
public void onDialogInteraction(String value) {
super.onDialogInteraction(value);
Log.d(TAG, "onDialogInteraction: value "+value);//prints correct value
Log.d(TAG, "onDialogInteraction: iaAdded "+isAdded()); false
Log.d(TAG, "onDialogInteraction: isAttahced "+isAttached());true
Log.d(TAG, "onDialogInteraction: isDetached "+isDetached());false
Log.d(TAG, "onDialogInteraction: isDetached "+getContext());null
}
}
public class MyActivity extends AppcompatActivity{
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String value = getValue(intent);
myFragmentInstance.onDialogInteraction(value);
}
}