title: How to declare a constant for extra in the returning intent in activity result API?
body: <p>Before, when i wanted to get a result from an activity, i did the following thing:</p>
  <pre><code>class SecondActivity extends AppCompatActivity{
      
      private final String EXTRA_ID = &quot;EXTRA_ID&quot;;
      private int someVar;
      
      .......
      
      private void someMethod(){
          Intent intent = new Intent();
          intent.setResult(EXTRA_ID, someVar);
      }
      
      public static int getSomeVar(Intent intent){
          if(intent == null)
              return -1;
          
          return intent.getIntExtra(EXTRA_ID);
      }
  }
  
  class FirstActivity extends AppCompatActivity{
  
      ...
      
      public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
          ...
              
          int x = SecondActivity.getSomeVar(data);
  
          ...
      }
      
      ...
  }
  </code></pre>
  <p>As you can see the extra is packaged and unpackaged in <code>SecondActivity</code>. In activity result API we have contracts in which unpackaging performs by <code>parseResult</code> method but packaging still performs in activity.</p>
  <p>An example of a contract:</p>
  <pre><code>public class MyOwnContract extends ActivityResultContract&lt;int, int&gt; {
  
      private final String EXTRA_CRIME_ID = &quot;com.bignerdranch.android.criminalintent.crime_id&quot;;
  
      .....
  
      @Override
      public int parseResult(int resultCode, @Nullable Intent intent){
          if(intent == null)
              return -1;
  
          return intent.getIntExtra(EXTRA_CRIME_ID);
      }
  }
  </code></pre>
  <p>So formerly we had one constant and one place where we used it (some activity or fragment), but now we have one constant and two places where we use it. What should i do with it ? I can decalre a public constant in the contract and when adding a variable in an extra just use it like this: <code>intent.setResult(someContract.EXTRA_ID, someVar)</code>. But in this case if we had a fragment instead of a activity, our fragment would loss independence and depend on the contract. Is there some right way to correctly declare a constant when using activity result API or the way above is the only one ?</p>