Everytime I try to show DialogFragment I get memory leaks.
This is how my test dialog (taken from android developers page) looks like:
public class TestDialog extends DialogFragment {
public static TestDialog newInstance(int title) {
TestDialog frag = new TestDialog();
Bundle args = new Bundle();
args.putInt("title", title);
frag.setArguments(args);
return frag;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int title = getArguments().getInt("title");
return new AlertDialog.Builder(getActivity())
.setIcon(R.drawable.ic_action_about)
.setTitle(title)
.setPositiveButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//((FragmentAlertDialog)getActivity()).doPositiveClick();
}
}
)
.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//((FragmentAlertDialog)getActivity()).doNegativeClick();
}
}
)
.create();
}
}
I launch it with following code which is executed on button press:
DialogFragment newFragment = TestDialog.newInstance(R.string.company_title);
newFragment.show(getFragmentManager(), "dialog");
How to solve this leak (or atleast hide it, because canaryleak is getting really annoying with all those notifications)?