偷懒代码块之Activity的Intent带参数跳转


	/**
	 * 启动任一Activity
	 * 注:在Activity中setClass和setComponent不能同时使用
	 */
	private void startActivity01(){
		ComponentName componentName = new ComponentName("cn.vjack.test", "cn.vjack.test.mainacitivity");//包名,类名
		Intent i = new Intent();
		i.setComponent(componentName);
		startActivity(i);
	}
	
	/**
	 * 传参启动Activity
	 */
	private void startActivity02(){
		ComponentName componentName = new ComponentName("cn.vjack.test", "cn.vjack.test.mainacitivity");//包名,类名
		Intent i = new Intent();
		Bundle b = new Bundle();
		b.putString("key", "value");
		b.putInt("number", 1);
		i.putExtras(b);
		i.setComponent(componentName);
		startActivity(i);
	}
	/**
	 * 接收Activity中获取传过来的数据
	 * 用于跳转后的Activity
	 */
	private void getActivityData(){
		Intent i = this.getIntent();
		String key = i.getStringExtra("key");
		int number = i.getIntExtra("number", 0);
	}


你可能感兴趣的:(源码,android)