Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not sure whether I got your question right, but passing data back <em>from</em> an activity is similar to passing data <em>to</em> an activity. You would probably start your worksheet with <a href="http://developer.android.com/reference/android/app/Activity.html#onActivityResult%28int,%20int,%20android.content.Intent%29" rel="nofollow"><code>startActivityForResult</code></a> and then take a look into the returned result data after returning in <a href="http://developer.android.com/reference/android/app/Activity.html#onActivityResult%28int,%20int,%20android.content.Intent%29" rel="nofollow"><code>onActivityResult</code></a>, which is wrapped into an <code>Intent</code>, too.</p> <p>Here's an example for emphasis.</p> <pre><code>public class CalculatorActivity extends Activity { /** Some locally unique identifier to recognize where you're coming from. */ private static final int RECQ_WORKSHEET = 1; /** * Some event that triggers your worksheet activity. */ public void onWorksheetButtonTouched( final View view ) { Intent intent = new Intent( this, WorksheetActivity.class ); startActivityForResult( intent ); } /** * Method which is called when returning from an activity * called with startActivityForResult. */ @Override public void onActivityResult( int requestCode, int result, Intent data ) { if( requestCode == REQC_WORKSHEET ) { // We're coming back from the worksheet here, so fetch the returned data. final String numberFromWorksheet = data.getStringExtra( WorksheetActivity.EXTRA_NUMBER ); ... } ... } } </code></pre> <p>Your worksheet activity would return its data wrapped into an <code>Intent</code> and store it with <a href="http://developer.android.com/reference/android/app/Activity.html#setResult%28int,%20android.content.Intent%29" rel="nofollow"><code>setResult</code></a>.</p> <pre><code>public class WorksheetActivity extends Activity { /** * Having accessible extra parameters enumerated in some way * makes your life (and the life of your colleagues) easier. * I've seen people adding _IN_, _OUT_ or _IO_ to emphasize * whether it's an input or output parameter, or both. */ public static final String EXTRA_NUMBER = "number"; ... /** * Some event which closes the worksheet activity. */ public void returnFromWorksheetButtonTouched( final View view ) { // Fetch the text you want to return. final EditText someText = (EditText) findViewById( R.id.someIdOfYourEditText ); final String value = someText.getText(); // Put it into an Intent. final Intent resultData = new Intent(); // note that we're using the no-args c'tor here resultData.putExtra( EXTRA_NUMBER, value ); // Now finish with this result. setResult( RESULT_OK, resultData ); finish(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload