Amrmsmb
Amrmsmb

Reputation: 11406

onAttach is not called

I have one activity and two fragments, Frag_1 and Frag_2. in both fragments i override onAttach method and there is a log message inside each onAttach method. when I run the App, the log message in the onAttach method of the Frag_1 is displayed while the log message in onAttach method in Frag_2 is never displayed. actually, I want to know why the onAttach in Frag2 is not called because I initialize an instance of an interface inside it.

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    iValuePasser = (IValuePasser) activity;
}

please let me know why the onAttch callbak is never called.

note App API level is 21

Upvotes: 1

Views: 768

Answers (1)

an_droid_dev
an_droid_dev

Reputation: 1136

Fragment have two methods called "onAttach" one of them was deprecated as documentation said Fragment

// you should override this
 @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    //Deprecated

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

Upvotes: 0

Related Questions