开发者

Problem passing Data within Activity

Intent intent = new Intent(this,AnotherClass.class);
intent.putExtra("Name", "foo");
setResult(RESULT_OK, null);

super.onActivityResult(requestCode, resultCode, d开发者_StackOverflowata);
    switch (requestCode) {
      case (1): {
        TextView textView = (TextView) findViewById(R.id.TextView01);
        if (resultCode == Activity.RESULT_OK) {
          textView.setText("Data" + data.getStringExtra("Name"));
        }

What am I doing wrong?


There are some things wrong. You dont set the Intent in the method setResult. Check this out: http://developer.android.com/reference/android/app/Activity.html#setResult(int,%20android.content.Intent)

You should pass the intent, instead of null.

Then remove super from onActivityOnResult. Your not calling onActivityOnResult, but your overriding it.

Then you're switching requestCode. Are you sure that RESULT_OK is 1? Otherwise it won't work. So it is better to use there also the constant RESULT_OK than 1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜