0
我必须从服务器获取数据,第一次当用户的土地上片段然后数据应在申请,除非用户登出坚持,但我想这样。如何摧毁片段实例变量用户注销后
public class AttendanceFragment : Fragment
{
private static ListView listView;
private static ProgressBar progress;
private static List<DA_ClassSectionAttendance> dataList=new List<DA_ClassSectionAttendance>();
// If i instantiate this variable 'dataList' here
//it will be persisted even the user logs out I know its declared as static
// because I am accessing this variable on broadcast receiver.
// But I want this re-instantiated after user logs out but HOW?
private static AttendanceListAdapter attendanceAdapter;
private static DA_Attendance daAttendance;
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// dataList = new List<DA_ClassSectionAttendance>(); if I instantiate this variable here everytime this fragment created or restores dataList.Count is zero or null
attendanceAdapter = new AttendanceListAdapter(this.Activity, dataList);
if((dataList==null || dataList.Count==0)) // pull data from server for the first time when fragment is created but I want this method call when user logs out as well.
{
GetClassSection(); // this method pulls data from server
}
//set whether MenuOption show/hide from toolbar
HasOptionsMenu = true;
}
谢谢
无论如何,可变静态变量在Android中是不好的做法 –