有没有办法让Activity知道它启动了什么resultCode?

时间:2012-08-23 21:33:46

标签: android android-activity

环顾四周,我似乎找不到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);

1 个答案:

答案 0 :(得分: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"); 
  }