onActivityResult对intent-data显示null

时间:2014-12-15 15:22:42

标签: java android onactivityresult

QuizActivity使用MainActivityV3启动startActivityForResult(),并在ArrayList中传递Bundle

ArrayList包含'Frage'类型的对象。 MainActivityV3修改了ArrayList的某些对象,并将其传递回QuizActivity

以下是代码的剪辑:

Frage.java

<pre>
    import java.io.Serializable;
    public class Frage implements Serializable {
       static final long serialVersionUID = 242526L;
       String frage;
       String antworta;
       String antwortb;
       String antwortc;
       String antwortd;
       int loesung;
    //following getter- and setter-Methods
       .
       .
    }

    //*** QuizActivity.java
      public Frage[] fragen;
      //array is filled with objects of type Frage
      .
      .
      void startInt() {
        Intent intent=new Intent(this,MainActivityV3.class);
        Bundle b = new Bundle();
        ArrayList mal=new ArrayList();
        for (Frage fr: fragen) {
            mal.add(fr); //Frage-Objects -> ArrayList
        }
        b.putSerializable("key", mal);
        intent.putExtras(b);
        startActivityForResult(intent,1);
      }
      .
      .
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
       //the parameter are 1,0 and null
        if (resultCode == Activity.RESULT_OK) {
          Bundle daten = data.getExtras();
          frList=(ArrayList)daten.getSerializable("key");
          int i=0;
          for (Frage f: frList) {
              fragen[i++]=f;
          }
        }
      } 
</pre>    


**MainActivityV3.java**

<pre>

    //modifying data of ArrayList, passing this back
    @Override
    public void onBackPressed() {
    Bundle b = new Bundle();
    Intent result=new Intent();
    //mal: the ArrayList, Debugger shows correctly the data
    b.putSerializable("key", mal); 
    result.putExtras(b);
    this.setResult(Activity.RESULT_OK,result);
    finish();
    }

</pre>

我的问题:onActivityResult()中的3个参数是1,0,null。为什么Intent参数null? 请帮帮我。

0 个答案:

没有答案