0

我们的应用程序有几个片段。其中一个用户填写了几个 TextEdit 字段。当他完成时,他按下 ActionBar 中的一个按钮来保存数据。Action 只是调用一个名为“saveData”的私有方法,该方法从字段中获取所有数据并将其提交到我们的服务器。

我们有许多来自用户的堆栈跟踪表明 getView() 在方法 saveData 中返回 null,但只是其中的一小部分。对于他们中的大多数人来说根本没有问题。我们无法重现该问题,也无法理解可能是什么原因造成的。代码非常简单:

View vw = this.getView();

EditText et;

et = (EditText)vw.findViewById(R.id.editEmail);
String email = et.getText().toString().trim();

et = (EditText)vw.findViewById(R.id.editPassword);
String password = et.getText().toString().trim();

该动作被添加到 osResume 中,见下图:

public void onResume() {
    super.onResume();

    MainActivity act = (MainActivity)this.getActivity();

    act.bar.removeAllActions(); 
    act.bar.addAction(new SaveAction()); 
}

有任何想法吗?我们如何重现它?

4

1 回答 1

0

Can you tell from your logs whether the problem is always for the same users / devices ?

I see from the code that you have submitted that the view is in the same fragment - is that actually the case ?

It's POSSIBLE that a fragment no longer in view can have their view destroyed in order to free up resources. e.g.

getView() returns null

If I suspected that this might be the case then I would attempt to recreate the problem on a phone / tablet / emulator with limited resources.

Good luck !

于 2013-07-06T21:24:24.393 回答