简体   繁体   English

从上次打开的活动中启动另一个应用程序意图(恢复)

[英]Launch another app intent from last open activity (resume)

I use the following code to launch other apps:我使用以下代码启动其他应用程序:

Intent intent = new Intent();
intent.addCategory(CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(packageName, activity));
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

This works however it makes the launched app start from the beginning, not from the last opened activity (resuming it).这可行,但是它使启动的应用程序从头开始,而不是从上次打开的活动(恢复它)开始。 Is there something wrong with my code?我的代码有问题吗?

Use a "launch Intent ", like this:使用“启动Intent ”,如下所示:

Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
startActivity(intent);

This Intent has all the necessary flags and settings to bring an existig task to the foreground or to start a new one (if the app is not running).Intent具有所有必要的标志和设置,可以将现有任务带到前台或启动新任务(如果应用程序未运行)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM