public class aActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.btn_a).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //显示启动Activity // Intent intent = new Intent(aActivity.this, bActivity.class); // startActivity(intent); //隐式启动Activity Intent intent = new Intent("com.anbeibei.intentprivate.test"); intent.addCategory("com.anbeibei.category.test"); startActivity(intent); } }); } }Manifest中a跟b配置,每个Intent只能指定一个action,能指定多个category
<activity android:name=".aActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".bActivity"> <intent-filter> <action android:name="com.anbeibei.intentprivate.test" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="com.anbeibei.category.test" /> </intent-filter> </activity> </application>
隐式启动一网页
Intent intent = new Intent(Intent.ACTION_VIEW);//安卓内置动作 intent.setData(Uri.parse("http://www.baidu.com"));//setData()接受当前intent操作的数据 intent-filter中在配置<data>标签更精确 startActivity(intent);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri url = Uri.parse("tel:电话号码");
intent.setData(url);
startActivity(intent);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri url = Uri.parse("网址");
intent.setData(url);
startActivity(intent);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivity(intent);
打开图库,如果想要返回图片,则用startActivityForResult
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTEA_TEXT,"文本内容");
startActivity(intent);