Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android导航堆栈的顶部启动活动_Android_Android Intent_Android Activity - Fatal编程技术网

在Android导航堆栈的顶部启动活动

在Android导航堆栈的顶部启动活动,android,android-intent,android-activity,Android,Android Intent,Android Activity,我正在使用TabHost中的活动实现TabActivity的解决方案,如中所述。我意识到这是次优的,但我已经走了相当远的路,只剩下一个打嗝。我需要跳转到我正在管理的堆栈顶部(使用活动ID的字符串列表),我知道我可以使用以下方法获得此活动: Activity current = getLocalActivityManager().getActivity(mIdList.get(0)); 但是,我不知道“显示”当前代码的方法 我知道我可以做到这一点: Activity current = getL

我正在使用
TabHost
中的活动实现
TabActivity
的解决方案,如中所述。我意识到这是次优的,但我已经走了相当远的路,只剩下一个打嗝。我需要跳转到我正在管理的堆栈顶部(使用活动ID的
字符串列表),我知道我可以使用以下方法获得此活动:

Activity current = getLocalActivityManager().getActivity(mIdList.get(0));
但是,我不知道“显示”当前代码的方法

我知道我可以做到这一点:

Activity current = getLocalActivityManager().getActivity(mIdList.get(1))
current.finish();
在堆栈上至少有两个活动的情况下,这将产生预期的结果。但是,当只有一个时,它会使用
BoundsException数组失败


如何“显示”给定的活动?

尝试以这种方式启动始终位于活动堆栈顶部的活动:

List<ActivityManager.RunningTaskInfo> processes1 = activityManager.getRunningTasks(1);
ComponentName componentInfo = processes1.get(0).topActivity;
String classname =processes1.get(0).topActivity.getClassName(); 
String packagename = processes1.get(0).topActivity.getPackageName();
if(classname.equalsIgnoreCase("com.YOUR_PACKAGE_NAME..YOURACTIVITY_NAME"))
    {
        Intent intent24 = new Intent(Intent.ACTION_MAIN).addCategory(
        Intent.CATEGORY_LAUNCHER).setClassName("YOUR_PACKAGE_NAME",
        "com.YOUR_PACKAGE_NAME..YOURACTIVITY_NAME").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        .addFlags(Intent.FLAG_FROM_BACKGROUND).setComponent(new ComponentName("YOUR_PACKAGE_NAME",
        "com.YOUR_PACKAGE_NAME..YOURACTIVITY_NAME"));
        getApplicationContext().startActivity(intent24);
    }
    else
    {
     //DONE SOMETHING HERE...
    }
List processes1=activityManager.getRunningTasks(1);
ComponentName componentInfo=processes1.get(0.topActivity);
字符串classname=processes1.get(0.topActivity.getClassName();
字符串packagename=processes1.get(0.topActivity.getPackageName();
if(classname.equalsIgnoreCase(“com.YOUR\u PACKAGE\u NAME..YOUR activity\u NAME”))
{
Intent intent24=新意图(Intent.ACTION\u MAIN).addCategory(
setClassName(“你的包名”,
“com.YOUR_PACKAGE_NAME..YOURACTIVITY_NAME”).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG来自\u后台).setComponent(新组件名称(“您的\u包\u名称”),
“com.YOUR_-PACKAGE_-NAME..YOUR-activity_-NAME”);
getApplicationContext().startActivity(intent24);
}
其他的
{
//在这里做了些什么。。。
}

尝试以下方法启动始终位于活动堆栈顶部的活动:

List<ActivityManager.RunningTaskInfo> processes1 = activityManager.getRunningTasks(1);
ComponentName componentInfo = processes1.get(0).topActivity;
String classname =processes1.get(0).topActivity.getClassName(); 
String packagename = processes1.get(0).topActivity.getPackageName();
if(classname.equalsIgnoreCase("com.YOUR_PACKAGE_NAME..YOURACTIVITY_NAME"))
    {
        Intent intent24 = new Intent(Intent.ACTION_MAIN).addCategory(
        Intent.CATEGORY_LAUNCHER).setClassName("YOUR_PACKAGE_NAME",
        "com.YOUR_PACKAGE_NAME..YOURACTIVITY_NAME").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        .addFlags(Intent.FLAG_FROM_BACKGROUND).setComponent(new ComponentName("YOUR_PACKAGE_NAME",
        "com.YOUR_PACKAGE_NAME..YOURACTIVITY_NAME"));
        getApplicationContext().startActivity(intent24);
    }
    else
    {
     //DONE SOMETHING HERE...
    }
List processes1=activityManager.getRunningTasks(1);
ComponentName componentInfo=processes1.get(0.topActivity);
字符串classname=processes1.get(0.topActivity.getClassName();
字符串packagename=processes1.get(0.topActivity.getPackageName();
if(classname.equalsIgnoreCase(“com.YOUR\u PACKAGE\u NAME..YOUR activity\u NAME”))
{
Intent intent24=新意图(Intent.ACTION\u MAIN).addCategory(
setClassName(“你的包名”,
“com.YOUR_PACKAGE_NAME..YOURACTIVITY_NAME”).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG来自\u后台).setComponent(新组件名称(“您的\u包\u名称”),
“com.YOUR_-PACKAGE_-NAME..YOUR-activity_-NAME”);
getApplicationContext().startActivity(intent24);
}
其他的
{
//在这里做了些什么。。。
}

首先检查大小
mIdList.size()
我知道,但是当
size()
==1时我该怎么办?mIdList.get(0)当其大小为1时。1元素,位置始终从索引0开始,项目编号为1如果大小为1,则堆栈中只有一个活动,并且您正在尝试第二个…使用
mIdList.get(1)
,所以在大小为1时使用
mIdList.get(0)
,我理解,但我希望始终显示活动0。通常,我会执行
activity.finish()
来获取
n-1
活动,但是如果
n
为1,那么程序将首先关闭检查大小
mIdList.size()
我知道,但是当
size()
==1时我该怎么做?mIdList.get(0)当其大小为1时。1元素,位置始终从索引0开始,项目编号为1如果大小为1,则堆栈中只有一个活动,并且您正在尝试第二个…使用
mIdList.get(1)
,所以在大小为1时使用
mIdList.get(0)
,我理解,但我希望始终显示活动0。通常,我会执行
activity.finish()
以获得
n-1
活动,但如果
n
为1,则程序将关闭。我将接受您的答案,因为我做了类似的操作(使用了
Intent
),但没有那么复杂。。。可能是错的。。。但这似乎奏效了Intent firstIntent=getLocalActivityManager().getActivity(mIdList.get(0)).getIntent();Window newWindow=getLocalActivityManager().startActivity(mIdList.get(0),firstIntent);setContentView(newWindow.getDecorView())`+1感谢您告诉我启动后台活动的新方法,但确保您的代码仅在您在活动中使用此代码时才起作用,但我的代码在服务和活动中都起作用,或者在广播接收器bez中起作用。我已经测试过。但朋友会得到答案。我会接受您的答案,因为我做了类似的事情(used
Intent
)但没有那么复杂。。。可能是错的。。。但这似乎奏效了Intent firstIntent=getLocalActivityManager().getActivity(mIdList.get(0)).getIntent();Window newWindow=getLocalActivityManager().startActivity(mIdList.get(0),firstIntent);setContentView(newWindow.getDecorView())`+感谢您告诉我启动后台活动的新方法,但确保您的代码仅在您在活动中使用此代码时才起作用,但我的代码在服务和活动或广播接收器bez中都起作用。我已对其进行了测试。但朋友会得到答案。