MainActivity parent=(MainActivity)getActivity();之前
onAttach()和之后你都做不到
onDetach()。
因为,您正在执行片段实例化时。该方法
getActivity将始终返回null。另外,尽量不要将
Activity参考文献保留在您的文档中
Fragment。如果未正确取消引用,则可能导致内存泄漏。
使用
getActivity()或
getContext()尽可能使用。
Toast如下更改:
Toast.makeText(getContext(), "Please check the number you entered", Toast.LENGTH_LONG).show();
要么
Toast.makeText(getActivity(), "Please check the number you entered", Toast.LENGTH_LONG).show();



