我的變量如下聲明:更新的TextView顯示用戶輸入的文本,Intent.getStringExtra()
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;
我不知道如何在onActivityResult完成代碼()方法。我不確定是否更新了正確顯示用戶輸入文本的Textview。我必須使用Intent.getStringExtra()。我用它,但作爲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");
}
}
}
}
非常感謝,但startActivityForResult(intent,GET_TEXT_REQUEST_CODE);給我一個錯誤。當我像這樣寫startActivityForResult(getIntent(),GET_TEXT_REQUEST_CODE)時就可以了; – user3284769
我編輯了答案,檢查它是否適合你。在意圖,請確保您使用的活動名稱 – ibpeco
謝謝!祝你好運 – user3284769