启动在其当前状态的活动 [英] Launching an activity at its current state

查看:133
本文介绍了启动在其当前状态的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个任务切换和我succed在里面。我唯一​​的问题是,当我发起的活动,他们被重新启动,因为他们是新的活动(比如,我写一封电子邮件,我preSS家,进入我的活动,推出电子邮件,然后应用程序启动电子邮件回合追溯到收件箱和电子邮件丢失),所以这不是真正的多任务。

I am trying to make a task switcher and i succed in it. My only problem is that when I launch activities, they are relaunched as they were new activities ( for instance, I am writing an email, i press home and go into my activity,launch email, and then the app launch the email bout goes back at the inbox and the email is lost) So that's not true multitasking.

下面是我的步骤:

1)让所有运行的应用程序:

1) getting all the running apps:

名单,其中,ActivityManager.RunningTaskInfo> allTask​​s = activityManager.getRunningTasks(30);

2)得到的意图:

的(ActivityManager.RunningTaskInfo aTask:allTask​​s){         意图I =新的意图(Intent.ACTION_MAIN);         i.setComponent(aTask.baseActivity); (...)

for (ActivityManager.RunningTaskInfo aTask : allTasks) { Intent i = new Intent(Intent.ACTION_MAIN); i.setComponent(aTask.baseActivity); (...)

3)上的按钮,点击时启动应用程序

3) Launching the application when clicking on the button:

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED).addCategory(Intent.CATEGORY_LAUNCHER);
    monthis.startActivity(intent);

`

什么是不对的code?我应该做不同的东西来得到它?

What is wrong with this code? Should I do something different to get it?

感谢很多的任何回答。

推荐答案

在创建你不应该使用Intent.FLAG_ACTIVITY_NEW_TASK的意图,你应该使用FLAG_ACTIVITY_REORDER_TO_FRONT。

When creating the Intents you should not use Intent.FLAG_ACTIVITY_NEW_TASK, you should use FLAG_ACTIVITY_REORDER_TO_FRONT.

这篇关于启动在其当前状态的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆