本文介绍了如何关闭所有子活动从家长的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人。其实一个处理程序在首页的活动正在运行的每30秒检查网络连接。

I'm new to android. Actually one handler is running in Home Activity A for every 30 sec to check the net connection.

如果我被A-> B->ç到活动C,如果在那个时候还没有网络连接的话,我想关闭活动B和C,然后想表现出活动A.消息框中

If I'm went to activity C by A->B->C, If there in no net connection at that time, then i want to close Activity B and C, then want to show message box in Activity A.

不过,我的问题是我的处理程序运行,每30秒,首页的活动A.但如果我是在练习C或其他一些活动如何找到这活动是我现在目前重点应用。然后,我要完成这些儿童的活动,并希望展示首页活动AI在活动B.某些9子活动

But My problem is My handler is running for every 30 sec in Home Activity A. But If i was in Activity C or some other Activity how to find which activity is my Application currently focussed now. Then i want to finish those child activities and want to show Home Activity A I have some 9 child activities in Activity B.

我听说过用FLAG_ACTIVITY_CLEAR_TOP。我用code在家庭活动A本身的处理程序如下。但遇到错误。

I heard about using "FLAG_ACTIVITY_CLEAR_TOP" . I used the code as follows in the handler in Home activity A itself. But got error.

        Intent intent = new Intent( ctx, Homepage.class );    
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | 
             Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    ctx.startActivity( intent );

下面Homepage.class是我的家活动A和我设置的清单文件中活性

Here Homepage.class is my Home Activity A and i set that activity in manifest file as

    android:launchMode="singleTop"    

请帮忙!

推荐答案

您可以启动一个活动,并关闭所有其他活动。你必须创建新的意图,并添加标志FLAG_ACTIVITY_CLEAR_TOP

You can start Activity A and close all other activities. You have to create new intent and add flag FLAG_ACTIVITY_CLEAR_TOP


Intent activityA = new Intent(context, ActivityA.class);
activityA.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.StartActivity(activityA);

这将关闭所有处于在堆栈,并在活动A

this will close all activities that are in the stack and are at the top of activity A

这篇关于如何关闭所有子活动从家长的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 22:45