如题发现桌面快捷只在简单的执行了Activity的onCreate,从而重新创建了进程,造成了资源浪费!有没办法点击快捷方式直接切换到后台的进程上?

解决方案 »

  1.   

    创建快捷方式的代码: 
           Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
            Parcelable iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
            shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
            shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
            shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setClass(this, MainActivity.class));
            sendBroadcast(shortcut);程序运行过程中,按home键把程序切换到后台,再通过上面创建的快捷方式进入程序,你会发现程序有两个进程,这时候如果软件上有退出功能的话,要退出两次才能返回到桌面!!!