Android Activity 回传数据

Adnroid用Intent来做activity的跳转,轻量级的数据用Bundle 配合着传递。

传回数据用startActivityForResult来搞。

跳转时代码:

_Intent=new Intent();
_Intent.setClass(getBaseContext(), Appearance.class);
startActivityForResult(_Intent, 1);

重载方法:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
       // TODO Auto-generated method stub
        Bundle _Bundle;
       switch (requestCode) {
       case 1:
           if (resultCode == RESULT_OK)
           {
               _Bundle = data.getExtras();
               String NAME= _Bundle.getString("NAME");
           }
           break;
       default:
           break;
       }
    }

另一个activity回传:

Intent _Intent = new Intent();             
                Bundle _Bundle = new Bundle(); 
                _Bundle.putString("NAME","LINCYANG");  
                _Intent.putExtras(_Bundle);                                   
                Appearance.this.setResult(RESULT_OK,_Intent);
                Appearance.this.finish();

就是这么简单~~~

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwspgx.html