活动结束之前发表的所有活动 [英] Finishing all activities started before the activity

查看:148
本文介绍了活动结束之前发表的所有活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要完成所有这一切都在想办法从堆栈中删除所有的家长活动运行的应用程序的活动。

I want to finish all the activities which are running in the application means want to remove all the parent activities from stack.

我想在本地实现我的应用程序注销功能,所以我在想什么,我会完成所有的活动之前开始,将重新开始登录活动。

I want to implement logout functionality locally in my application so what I was thinking, I will finish all the activities started before and will start login activity again..

推荐答案

我应该让你知道这是不是在Android的推荐行为,因为你应该让自己来管理活动的生活圈子。

I should let you know this is not a recommended behavior in android since you should let itself to manage life circles of activities.

不过,如果你真的需要做到这一点,你可以使用<一个href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP">FLAG_ACTIVITY_CLEAR_TOP

However if you really need to do this, you can use FLAG_ACTIVITY_CLEAR_TOP

我给你一些示例code在这里,在这里MainActivity是在应用程序中的第一个活动

I give you some sample code here, where MainActivity is the first activity in the application:

public static void home(Context ctx) {
    if (!(ctx instanceof MainMenuActivity)) {
        Intent intent = new Intent(ctx, MainMenuActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        ctx.startActivity(intent);
    }
}

如果你想退出整个应用程序,您可以使用下面的code和检查的MainActivity完全退出该应用程序:

If you want to quit whole application, you can use the following code and check in the MainActivity to quit the application completely:

    public static void clearAndExit(Context ctx) {
    if (!(ctx instanceof MainMenuActivity)) {
        Intent intent = new Intent(ctx, MainMenuActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        Bundle bundle = new Bundle();
        bundle.putBoolean("exit", true);
        intent.putExtras(bundle);
        ctx.startActivity(intent);
    } else {
        ((Activity) ctx).finish();
    }
}

希望这有助于。

Hope this helps.

这篇关于活动结束之前发表的所有活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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