The snippet isAdded returns false and isAttached returns true
I call a method in an activity when I am on one of the fragments and then return the result of the method to the activity on the same fragment I am on, but surprisingly this gives me an error since the fragment has not been added yet. I am printing the isAttached and isDetached values ββand the true and false values ββrespectively. Also getContext returns null. How is this possible?
This method calls the return of the expected values ββbefore calling the method.
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);
}
}
+3
source to share
No one has answered this question yet
Check out similar questions: