diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-02-12 22:31:14 +0100 | 
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-11-10 17:40:54 +0100 | 
| commit | 3c228228209bb186ab6881eb9b9bae10c1d5c893 (patch) | |
| tree | ef617fcc2184c5a9542ecfb5c165ae3f1c546820 /Android/02-Intents/IntentsLab/src/course/labs | |
| parent | ee3ef2bcf3656e3e7a02d86d43858cc8145508da (diff) | |
| download | coursera-3c228228209bb186ab6881eb9b9bae10c1d5c893.zip coursera-3c228228209bb186ab6881eb9b9bae10c1d5c893.tar.gz  | |
Android : 02-Intents: implement
Diffstat (limited to 'Android/02-Intents/IntentsLab/src/course/labs')
| -rw-r--r-- | Android/02-Intents/IntentsLab/src/course/labs/intentslab/ActivityLoaderActivity.java | 27 | ||||
| -rw-r--r-- | Android/02-Intents/IntentsLab/src/course/labs/intentslab/ExplicitlyLoadedActivity.java | 8 | 
2 files changed, 17 insertions, 18 deletions
diff --git a/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ActivityLoaderActivity.java b/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ActivityLoaderActivity.java index 407b371..abd912a 100644 --- a/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ActivityLoaderActivity.java +++ b/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ActivityLoaderActivity.java @@ -56,30 +56,29 @@ public class ActivityLoaderActivity extends Activity {      // Start the ExplicitlyLoadedActivity      private void startExplicitActivation() {          Log.i(TAG,"Entered startExplicitActivation()"); -        // TODO - Create a new intent to launch the ExplicitlyLoadedActivity class -        // TODO - Start an Activity using that intent and the request code defined above +        Intent intent = new Intent(ActivityLoaderActivity.this, ExplicitlyLoadedActivity.class); +        startActivityForResult(intent, GET_TEXT_REQUEST_CODE);      }      // Start a Browser Activity to view a web page or its URL      private void startImplicitActivation() {          Log.i(TAG, "Entered startImplicitActivation()"); -        // TODO - Create a base intent for viewing a URL -        // (HINT:  second parameter uses parse() from the Uri class) -        // TODO - Create a chooser intent, for choosing which Activity -        // will carry out the baseIntent. Store the Intent in the -        // chooserIntent variable below. HINT: using the Intent class' -        // createChooser()) -        Intent chooserIntent = null; +        Uri webpage = Uri.parse("http://asynk.ch"); +        Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage); +        Intent chooserIntent = Intent.createChooser(webIntent, "Choose damn it!");          Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction()); -        // TODO - Start the chooser Activity, using the chooser intent -        startActivity(chooserIntent); +        if (chooserIntent.resolveActivity(getPackageManager()) != null) { +            startActivity(chooserIntent); +        }      }      @Override      protected void onActivityResult(int requestCode, int resultCode, Intent data) {          Log.i(TAG, "Entered onActivityResult()"); -        // TODO - Process the result only if this method received both a -        // RESULT_OK result code and a recognized request code -        // If so, update the Textview showing the user-entered text. +        if (requestCode == GET_TEXT_REQUEST_CODE) { +            if (resultCode == RESULT_OK) { +                mUserTextView.setText(data.getStringExtra("data")); +            } +        }      }  } diff --git a/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ExplicitlyLoadedActivity.java b/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ExplicitlyLoadedActivity.java index 5c33228..80c19f8 100644 --- a/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ExplicitlyLoadedActivity.java +++ b/Android/02-Intents/IntentsLab/src/course/labs/intentslab/ExplicitlyLoadedActivity.java @@ -39,9 +39,9 @@ public class ExplicitlyLoadedActivity extends Activity {      // Sets result to send back to calling Activity and finishes      private void enterClicked() {          Log.i(TAG,"Entered enterClicked()"); -        // TODO - Save user provided input from the EditText field -        // TODO - Create a new intent and save the input from the EditText field as an extra -        // TODO - Set Activity's result with result code RESULT_OK -        // TODO - Finish the Activity +        Intent intent = new Intent(); +        intent.putExtra("data", mEditText.getText().toString()); +        setResult(RESULT_OK, intent); +        finish();      }  }  | 
