I hope someone can help. I have a non activity class in which I need to access the fragmentmanager in a static method, unfortunatly I don`t know how to pass the context correctly.
Any help is appreciated,
Non activity class:
public class testClass {
..
public synchronized static void checkNewdata(List<data>input, Context context) {
..
FragmentManager ft = ((FragmentActivity)???).getSupportFragmentManager();
DialogFragment newFragment = MyNotification.newInstance();
newFragment.setCancelable(false);
newFragment.show(ft, "mydialog");
..
}
}
The method checkNewdata is also being called from a non activity class, in which I try to pass context but this doesn`t work:
public class SearchResponse extends SuccessResponse {
private Context mcontext;
public SearchResponse(Context context){
mcontext = context;
}
..
@Override
public void save() {
..
testClass.checkNewdata(mainData, context);
..
}
}
Context
reference in a static method is a bad idea. I suggest you to rethink your design rather than searching for a workaround. – Cirrocumulus