Reputation: 63
My variables are declared below:
static private final int GET_TEXT_REQUEST_CODE = 1;
static private final String URL = "http://www.google.com";
static private final String TAG = "Lab-Intents";
static private final String CHOOSER_TEXT = "Load " + URL + " with:";
private TextView mUserTextView;
I'm not sure how to complete code in onActivityResult() method. I'm not sure if I updated the Textview showing the user-entered text correctly. I have to use Intent.getStringExtra(). which I used but as getIntent().getStringExtra("mUserTextView");
private void startImplicitActivation() {
Log.i(TAG, "Entered startImplicitActivation()");
Uri url = Uri.parse(URL);
Intent baseIntent = new Intent(Intent.ACTION_VIEW, url);
Intent chooserIntent = Intent.createChooser(baseIntent, CHOOSER_TEXT);
Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
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 (requestCode == RESULT_OK){
getIntent().getStringExtra("mUserTextView");
}
}
}
}
Upvotes: 1
Views: 4014
Reputation: 1
chooserIntent is null. First create it : Intent chooserIntent = Intent.createChooser(map, CHOOSER_TEXT);
Upvotes: 0
Reputation: 1
The static method createChooser(Intent, CharSequence)
from the type Intent should be accessed in a static way. This is shown when I'm running the same code at chooserIntent.createChooser(map,CHOOSER_TEXT);
//CODE
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)
Intent map = new Intent(Intent.ACTION_VIEW,Uri.parse(URL));
// 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;
chooserIntent.createChooser(map,CHOOSER_TEXT);
Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
// TODO - Start the chooser Activity, using the chooser intent
startActivity(chooserIntent);
}
This causes an error when I'm running the app as:
unfortunately the project has stopped
Upvotes: 0
Reputation: 58
To update the label, you should use:
if ( resultCode == RESULT_OK && requestCode == GET_TEXT_REQUEST_CODE ) {
mUserTextView.setText( data.getStringExtra("resultado"));
}
Remember to call "ExplicitlyLoadedActivity", with the request code GET_TEXT_REQUEST_CODE:
Intent myIntent = new Intent(ActivityLoaderActivity.this, ExplicitlyLoadedActivity.class);
startActivityForResult( myIntent, GET_TEXT_REQUEST_CODE ); // just to be sure about Request code
Change the word "resultado", for the one you used in enterClicked() for ExplicitlyLoadedActivity
String givenText = mEditText.getText().toString(); // Getting the user input
Intent intencion = new Intent(); // Getting ready to comeback
intencion.putExtra("resultado", givenText); // I use "resultado", spanish guy
setResult(RESULT_OK, intencion); // RESULT_OK is a constant = 1
finish();
Good luck width the lab in coursera, also I'm doing it. Cheers
Upvotes: 2