两个app之间的数据相互调用

场景:A 跳转 B 传输数据,在 B 中执行操作后,返回并携带数据 A

A代码示例:

			String action = "com.feng.action.customAction"
      		Intent intent = new Intent(action); 
            intent.putExtra("action", "action");
            startActivityForResult(intent, REQUEST_CODE_1);
            
 //       **************************************分割线*******************************************
 			@Override
    		protected void onActivityResult(int requestCode, int resultCode,  Intent data) {
        		if (requestCode == REQUEST_CODE_1) {
            		String res = data.getStringExtra("result");
            		Toast.makeText(getBaseContext(), "收到:" + res, 0).show();
        		} else
            	super.onActivityResult(requestCode, resultCode, data);
    		}

B代码示例:

清单文件:

		
  			
                
                
            
                 

Activity:

			Intent intent = getIntent();
            String act= intent.getStringExtra("action");
            Log.e("action",act);
            
//       **************************************分割线*******************************************            
//           在点击事件中
            Intent resultIntent = new Intent();
            resultIntent.putExtra("result", "B返回结果了");
           	setResult(Activity.RESULT_OK, resultIntent);
            this.finish();

你可能感兴趣的:(Android)