• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Crossed out onAttach(activity) = deprecated ?

ac4android

Well-Known Member
Hi, I was creating an interface (listener) between a fragment and an activity, using the onAttach() method

AS crossed out the method name and wen I hover over it with the pointer, it says "deprecated".

Can I still use the onAttach() method?

I am too new to Java :(

DeprecatedMethod.JPG
 

Attachments

  • DeprecatedMethod.JPG
    DeprecatedMethod.JPG
    17 KB · Views: 103
This worked for me when i have userdefind interface 'TopSectionFragment' and its object activitycommander:

//This method gets called whenever we attach fragment to the activity
@override
public void onAttach(Context context) {
super.onAttach(context);
Activity a=getActivity();
try {
if(context instanceof Activity)
this.activitycommander=(TopSectionListener)a;
}catch (ClassCastException e){
throw new ClassCastException(a.toString());}

}
 
Back
Top Bottom