一、交互代码笔记:
private LoginFragmentListener mListener;
@Override
public void onAttach(Activity activity)
{
super.onAttach(activity);
try
{
mListener = (LoginFragmentListener) activity;
}
catch (ClassCastException e)
{
// throw new ClassCastException(activity.toString() + "must implement LoginFragmentListener");
Log.e("接口实现异常", activity.toString() + "未实现LoginFragmentListener接口!");
}
}
// 监听登录验证结果的接口
public interface LoginFragmentListener
{
// 登录完毕
public void OnLoginComplete(String result);
// 登录失败
public void OnLoginFailed(String result);
// 退出成功
public void OnLoginOutFailed(String mSessionId);
// 退出失败
public void OnLoginOutComplete(String result);
}
二、重写finish退出最后一个fragment
/**
* 重写finish,当fragment栈中只剩最后一个fragment时才finish
*/
@Override
public void finish()
{
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
{
super.finish();
}
else
{
getSupportFragmentManager().popBackStack();
}
}
转载于:https://blog.51cto.com/glblong/1322346