Intent1.1

				Intent intent = new Intent();
				ComponentName comName = new ComponentName(MainActivity.this, MainActivity2.class);
				intent.setComponent(comName);
				startActivity(intent);

 

配置Action Category:  默认Category:

<activity 
            android:name="com.example.android_intent.MainActivity2">
			<intent-filter>
				<action android:name="sb"/>
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>            
        </activity>
				Intent intent = new Intent();
		    	intent.setAction("sb");
		    	startActivity(intent);

 

多个竞争,则跳出选择框:

<activity 
            android:name="com.example.android_intent.MainActivity2">
			<intent-filter>
				<action android:name="sb"/>
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>            
        </activity>
        
        <activity 
            android:name="com.example.android_intent.MainActivity3">
			<intent-filter>
				<action android:name="sb"/>
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>            
        </activity>

 

添加Category:

<activity 
            android:name="com.example.android_intent.MainActivity3">
			<intent-filter>
				<action android:name="sb"/>
				<category android:name="sbb" />
				<category android:name="android.intent.category.DEFAULT" />
			</intent-filter>            
        </activity>

 

				Intent intent = new Intent();
		    	intent.setAction("sb");
		    	intent.addCategory("sbb");
		    	startActivity(intent);

 代码中如果addCategory多个类别,则必须都要满足,否则匹配失败!

 

				Intent intent = new Intent();
		    	intent.setAction(Intent.ACTION_VIEW);
		    	Uri data = Uri.parse("http://www.baidu.com");
		    	intent.setData(data);
		    	startActivity(intent);

 查看图片:

    	Intent intent = new Intent();
		intent.setAction(Intent.ACTION_VIEW);
		Uri data = Uri.parse("file:///sdcard/Camera/P31105-220549-001.jpg");
		intent.setDataAndType(data,"image/jpg");
		startActivity(intent);

 

你可能感兴趣的:(intent)