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
java android android-fragments android-fragmentactivity


source to share


No one has answered this question yet

Check out similar questions:

1158
"Override superclass method" Errors after importing project into Eclipse
462
ViewPager and Fragments - What's the correct way to store the state of a Fragment?
261
Understanding the setRetainInstance (boolean) snippet
17
Error: onNewIntent is not called for singleTop activity with Intent.FLAG_ACTIVITY_NEW_TASK
eleven
Fragment of OnClickListener called after onDestroyView
4
fragment isInLayout returns false
1
getStringExtra returns null, after multiple intents
0
Google plus login activity with snippet
-2
when the mesg box comes out it goes back to prevoius activyty
-2
This is the use of the nav drawer and the use of the tab and also the use of the snippet. how is the relationship between FragmentActivity and Fragment?



All Articles
Loading...
X
Show
Funny
Dev
Pics