摘自
http://www.linuxidc.com/Linux/2011-02/31966.htm
打开程序的入口有很多个:
shell 命令行运行;
Launcher待机界面执行;
状态通知栏运行;
桌面快捷方式运行;
软件中调用运行;
安装软件后执行“OPEN”运行!
前面几项,调用程序的代码如下(参考:com.android.Launcher/.Launcher.java):
打开程序的入口有很多个:
shell 命令行运行;
Launcher待机界面执行;
状态通知栏运行;
桌面快捷方式运行;
软件中调用运行;
安装软件后执行“OPEN”运行!
前面几项,调用程序的代码如下(参考:com.android.Launcher/.Launcher.java):
Intent intent = new Intent(this, TestActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
this.startActivity(intent);
而安装软件后,点击“Open”调用的代码如下(参考:com.android.packageinstaller/.InstallAppDone.java):
Intent intent = new Intent(this, TestActivity.class);
this.startActivity(intent);
如果用户安装软件后立刻执行“Open”,运行程序后,按HOME键返回到后台,然后再通过别的几种方法运行程序,则会再起一个MAIN程序。这是因为Intent的处理机制是,先比较Activity,再比较Action、Flag、bnds。。。,前后两张方式的Action不一样,一个有LAUNCHER ACTION,一个没有,所以会认为是启动两个不同的INTENT。