想将MyActivity中exidtext中输入的字符传到MainActivity中的textview'中,但是运行过后,textview并无显示。
MyActivity的程序: protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        Button btn=(Button)findViewById(R.id.Button11);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            String site1=((EditText)findViewById(R.id.EditText11)).getText().toString();
                String site2=((EditText)findViewById(R.id.EditText12)).getText().toString();                    Intent intent=new Intent(MyActivity.this,MainActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putString("site1",site1);
                    bundle.putString("site2",site2);
                    intent.putExtras(bundle);
                    setResult(0x11,intent);
                    finish();            }
        });
    }
}
MainActivity的     相关      程序:
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==0x11 && resultCode==0x11){
            Intent intent=getIntent();
            Bundle bundle=intent.getExtras();
            String pianshu=bundle.getString("site1");
            String yeshu=bundle.getString("site2");
            tv_msg.setText(pianshu);
            TextView1.setText(yeshu);
        }
    }    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);        tv_msg = (TextView) findViewById(R.id.tv_msg);
        TextView1=(TextView) findViewById(R.id.TextView1);
        ed_msg =(EditText) findViewById(R.id.EditText1);
        btn_send =(Button) findViewById(R.id.Button1);        Button button2=(Button)findViewById(R.id.Button2);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(MainActivity.this, MyActivity.class);
                startActivityForResult(intent1,0x11);
            }
        });
日志:
03-13 12:57:24.910 2782-2789/com.liuhuan W/art: Suspending all threads took: 5.597ms
03-13 12:57:25.660 2782-2807/com.liuhuan W/EGL_emulation: eglSurfaceAttrib not implemented
03-13 12:57:25.661 2782-2807/com.liuhuan W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa265b8a0, error=EGL_SUCCESS
03-13 12:57:25.802 2782-2807/com.liuhuan E/Surface: getSlotFromBufferLocked: unknown buffer: 0xabaf9040
03-13 12:57:25.820 2782-2807/com.liuhuan D/OpenGLRenderer: endAllStagingAnimators on 0xa25c6d00 (RippleDrawable) with handle 0xa2624890
新人跪求指导!

解决方案 »

  1.   

    你传递值那里应该  
    Intent intent=new Intent(MyActivity.this,MyActivityTwo.class);
                    Bundle bundle=new Bundle();
                    bundle.putString("site1",site1);
                    bundle.putString("site2",site2);
                    intent.putExtra("data",bundle);  这样传递  ,
    而接受值应该在     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            String pianshu =  getIntent().getBundleExtra("data").getString("site1","ddd");
            String yeshu= getIntent().getBundleExtra("data").getString("site2","ddd");
            tv_msg = (TextView) findViewById(R.id.tv_msg);
            TextView1 = (TextView) findViewById(R.id.TextView1);
            ed_msg = (EditText) findViewById(R.id.EditText1);        btn_send = (Button) findViewById(R.id.Button1);        tv_msg.setText(pianshu);
            TextView1.setText(yeshu);
            Button button2 = (Button) findViewById(R.id.Button2);
            button2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent1 = new Intent(MyActivityTwo.this, MyActivity.class);
                    startActivityForResult(intent1, 0x11);
                }
            });
      

  2.   


    我按照你说的改了没用还是没有显示,我没有系统的学过安卓,只是大概了解了一下,就是为了搞这个监控的小程序,所以可能会犯些低级错误,有没有哪里可能会出错的?或者你留个qq之类的?万分感谢!
    加我微信吧kylin__0
      

  3.   


    我按照你说的改了没用还是没有显示,我没有系统的学过安卓,只是大概了解了一下,就是为了搞这个监控的小程序,所以可能会犯些低级错误,有没有哪里可能会出错的?或者你留个qq之类的?万分感谢!
    加我微信吧kylin__0
    没找到这个微信号,可以加我一下吗:lh729284143
      

  4.   

    你觉得你启动myactivity的时候, 根本没有使用startActivityForResult.最好是调试下吧. 下个断点, 看程序执行到哪里, 相关变量值又是多少.
    重点是要在onActivityResult  函数内部下断点, 看是否执行到相关代码
      

  5.   

    大兄弟,你接受的时候不能getintent(),getIntent()获取的是上一个页面传递过来的参数,不是回调过来的,回调过来的是onActivityResult(int requestCode, int resultCode, Intent data) 里面的data参数,怪不得你收不到