我的应用程序的当前实现有问题。我执行 asynctask onActivityCreated 但如果用户只是更改手机的方向,我对此不感兴趣。当用户改变手机的方向时,确保不进行不必要的异步调用的正确方法是什么?
这里有两个方法onActivityCreated 和populateList。populateList 被称为 onPostExecute()。
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
userControl = new UserController(getSherlockActivity());
lv = (ListView)getView().findViewById(R.id.callforwardlist);
lv.setTextFilterEnabled(true);
list = new ArrayList<HashMap<String,String>>();
callForwardList = new SimpleAdapter(
getSherlockActivity(),
list,
R.layout.callforward_items,
new String[] { "line1","line2" },
new int[] { R.id.callforward_item_text, R.id.callforward_number } );
new PullInfoTask().execute();
lv.setAdapter( callForwardList );
lv.setOnItemClickListener(new OnItemClickListener() {
// *snip*
});
}
private void populateList()
{
cfinfo = userControl.GetCallForwardInfo();
if(Integer.parseInt( cfinfo[0]) == 1)
addItem("Viderestilling altid", cfinfo[1]);
else
addItem("Viderestilling altid", "Slået fra");
if(Integer.parseInt(cfinfo[2]) == 1)
addItem("Viderestilling ved optaget", cfinfo[3]);
else
addItem("Viderestilling ved optaget", "Slået fra");
if(Integer.parseInt(cfinfo[4]) == 1)
addItem("Viderestilling ved intet svar", cfinfo[5]);
else
addItem("Viderestilling ved intet svar","Slået fra");
// Timeout Item
addItem("Timeout",cfinfo[6]);
callForwardList.notifyDataSetChanged();
}