两个Activities之间的数据传递问题解决1

//Main Activity
        mSearchBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				
				intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
				intent.setClass(getApplicationContext(), SearchActivity.class);
				//If you wanna get the values from the SearchActivity, //then,you have to set them "Before SearchActivity get them"!!!!
				bundle.putString("item", null);
				bundle.putString("category", null);
				bundle.putString("page",null);
				intent.putExtras(bundle);
				startActivityForResult(intent, 1);
			}
		});
          
    }//onCreate
    
    /**
     *  Receive from the SearchActivity 
     * 
     *  @override
     * **/
        @Override
		protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        	
			super.onActivityResult(requestCode, resultCode, data);
			switch(resultCode){
			case RESULT_OK:
				Log.d("return","Return OK!");
				/* Get result from SearchActivity */
				bundle = data.getExtras();
				String item = bundle.getString("item");
				String category = bundle.getString("category");
				String page = bundle.getString("page");
				Log.d("result","item-category-page="+item+category+page);
				break;
			default:
				break;
			}
		}

//SearchActivity.java

//Get the bundle in the intent
        intent = this.getIntent();
        bundle = intent.getExtras();
        mBtn_back.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				bundle.putString("item", "whatItem");
				bundle.putString("category", "whatCate");
				bundle.putString("page","whatPage");
				intent.putExtras(bundle);
				SearchActivity.this.setResult(RESULT_OK, intent);
				SearchActivity.this.finish();
			}
		});


你可能感兴趣的:(两个Activities之间的数据传递问题解决1)