首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

经过包名启动程序

2012-09-05 
通过包名启动程序之前在启动外部程序都是通过包名和类名来启动,如下:Intent intent new Intent()intent

通过包名启动程序
之前在启动外部程序都是通过包名和类名来启动,如下:

Intent intent = new Intent();intent.setClassName(packageName, activityName);startActivity(intent);


现在又发现了另一种只要通过包名就可以启动的方法,支持1.5及以上:
Intent intent =getPackageManager().getLaunchIntentForPackage(packageName);startActivity(intent);


public abstract Intent getLaunchIntentForPackage(String packageName)
Since: API Level 3
api解释如下:
Return a "good" intent to launch a front-door activity in a package, for use for example to implement an "open" button when browsing through packages. The current implementation will look first for a main activity in the category CATEGORY_INFO, next for a main activity in the category CATEGORY_LAUNCHER, or return null if neither are found. Throws PackageManager.NameNotFoundException if a package with the given name can not be found on the system.

热点排行