summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android/02-Intents/IntentsLab/src/course/labs/intentslab/ActivityLoaderActivity.java27
-rw-r--r--Android/02-Intents/IntentsLab/src/course/labs/intentslab/ExplicitlyLoadedActivity.java8
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();
}
}