Android的,如何把任务推到前台?推到、前台、任务、Android

由网友(对你的以后不打扰i)分享简介:我的问题:我怎么能推出自己的任务一个新的活动,同时使用下列规则。 How can I launch a new Activity in its own Task while using the following rules. 1)如果该活动已经作为另一个任务(在同一程序中的根目录),然后把任务推到前台。我不想要...

我的问题:

我怎么能推出自己的任务一个新的活动,同时使用下列规则。

How can I launch a new Activity in its own Task while using the following rules.

1)如果该活动已经作为另一个任务(在同一程序中的根目录),然后把任务推到前台。我不想要创建的活动的另一个实例。我只想任务,这是前来前景和任务的顶部活动要显示的根源。

1) If the Activity already exists as a root of a another Task (within the same application) then bring the Task to the foreground. I don't want another instance of the Activity to be created. I just want the Task that it is the root of to come to the foreground and the top Activity of the Task to be displayed.

请注意:它只有一个任务的根的时间和它只会存在任务的根,无处

Note: it will only be the root of one Task at a time and it will only exist as the root of the Task and nowhere else.

2)如果活动不存在则创建该活动在自己的任务。

2) If the Activity doesn't exist then create this Activity in its own Task.

为什么我想要实现这一目标? 我创建了四个底部在我活动的底部应该表现得像选项卡,。所以,如果我preSS的第二个标签我要与将要显示的选项卡相关联的活动。但是,如果它已经存在,是对自己工作的底部,那么我想这项任务与任何活动与目前任务的顶部显示。

Why I'm trying to achieve this? I created four bottoms at the bottom of my Activities that should behave like tabs. So if I press the second "tab" I want the Activity that is associated with that tab to be displayed. But if it already exist and is on the bottom of its own Task then I would like that Task to be displayed with whatever Activity that is currently on the top of the Task.

有什么我想这么远吗? 我搜索计算器,但没有找到类似的问题。我读 http://developer.android.com/guide /topics/fundamentals/tasks-and-back-stack.html 和的http://blog.akquinet.de/2010/04/15/android-activites-and-tasks-series-intent-flags/

What have I tried so far? I've searched stackOverflow and couldn't find a similar question. I read http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html and http://blog.akquinet.de/2010/04/15/android-activites-and-tasks-series-intent-flags/

我想我需要为使用FLAG_ACTIVITY_NEW_TASK和/或亲和力,但不能确定。寻找一只手吧。

I think I need to use either FLAG_ACTIVITY_NEW_TASK and/or affinities but not sure. Looking for a hand please.

谢谢, Bradley4

Thanks, Bradley4

推荐答案

我能解决这个问题的Andr​​oid版本> =蜂窝:

I was able to solve this for Android version >= Honeycomb:

@TargetApi(11)
protected void moveToFront() {
    if (Build.VERSION.SDK_INT >= 11) { // honeycomb
        final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

        for (int i = 0; i < recentTasks.size(); i++) 
        {
               Log.d("Executed app", "Application executed : " 
                       +recentTasks.get(i).baseActivity.toShortString()
                       + "tt ID: "+recentTasks.get(i).id+"");  
               // bring to front                
               if (recentTasks.get(i).baseActivity.toShortString().indexOf("yourproject") > -1) {                     
                  activityManager.moveTaskToFront(recentTasks.get(i).id, ActivityManager.MOVE_TASK_WITH_HOME);
               }
        }
    }
}

您还需要添加到您的清单:

you also need to add these to your manifest:

<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
阅读全文

相关推荐

最新文章