Android中Activity的启动方式大致有以下两种:
1、显式启动
显式启动是我们日常开发中必不可少,基本上每天都会写的
Intent intent = new Intent(MainActivity.this,OtherActivity.class);
startActivity(intent);
2、隐式启动
与显式启动不同之处在于使用隐式启动需要在我们AndroidManifest.xml清单配置文件中的所需启动的Activity中添加过滤器如下:
<activity android:name=".OtherActivity">
<intent-filter>
<action android:name="com.ghost.deng.OTHER">
<category android:name = "android.intent.catrgory.DERAULT">
</intent-filter>
</activity>
然后在我们的Activity中进行隐式启动
Intent intent = new Intent("com.ghost.deng.OTHER");
startActivity(intent);
使用隐式启动我们不仅可以启动自己的Activity,还可以启动其他的Activtiy,例如打电话也是通过隐式启动来实现的
Intent intent = new Intent(Intent.ACTION_CALL);
Uri data = Uri.parse("tel:"+phoneNum);
intent.setData(data);
startActivity(intent);
同理我们可以想像,别人如果知道我们的这个action是不是就可以跳转到我们对应的Activity了呢?
答案是肯定的,那么如果我们的意图即action里的这个name与其他应用程序里面的Activity相同时会怎么样呢?
系统会让你选择打开其中一个
如果一个都没有的话,系统就会报错.