0

环顾四周,我似乎找不到任何方法Activity来确定resultCode它是从什么开始的。例子:

class A extends Activity {
   void yadda() {
      Intent intent = new Intent(this, B.class);
      startActivityForResult(intent, 8675309);
   }
}


class B extends Activity {
   void yadda() {
      int code = getTheResultCode(); // I want to get 8675309
   }
}

我必须把它放进去Intent吗?

intent.putExtra("resultCode", 8675309);
4

1 回答 1

3

在知道resultCode的Activity中:

  Intent i = new Intent(getApplicationContext(), NewActivity.class); 
  i.putExtra("resultCode",resultCode); 
  startActivity(i); 

在下一个活动中

  Bundle extras = getIntent().getExtras(); 
  if (extras != null) { 
     String resultCode= extras.getString("resultCode"); 
  } 
于 2012-08-23T21:36:17.437 回答