如何从android back stack删除特定活动? [英] How to remove a particular activity from android back stack?

查看:88
本文介绍了如何从android back stack删除特定活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有五个活动a,b,c,d,e.用户按以下顺序中转.... 1. a-> b 2. b-> c 3. c-> d 4. d-> e

In my application, i have five activity a,b,c,d,e. User transits in following sequence.... 1. a -> b 2. b -> c 3. c -> d 4. d -> e

直到活动"d",如果用户按下后退"按钮,应用程序应将用户重定向到上一个活动,例如d-> c,c-> b等...

up to the activity 'd', if user presses the back button, application should redirect user to the previous activity like d -> c , c -> b and so on...

但是,当用户单击活动"d"中的保存"按钮时,应用程序会将用户重定向到活动"e".现在,如果用户按下后退"按钮,则我要将用户重定向到活动"a",即活动屏幕显示在我的应用程序中.

But when user click's on save button in activity 'd', application will redirect user to the activity 'e'.now if user presses the back button then i want to redirect user to the activity 'a',which is home screen in my application.

我对android完全陌生.我不知道该如何实现此流程.我尝试了此解决方案,但还没有没有取得理想的结果.对不起,我英语不好...

I am completely new to the android. I don't know how to achieve this flow.I tried this solution but it hasn't yielded desired result. and sorry for my bad English...

推荐答案

一并尝试.

// Add activity
public static void addActivities(String actName, Activity _activity) {
    if (Config.screenStack == null)
        Config.screenStack = new HashMap<String, Activity>();
    if (_activity != null)
        Config.screenStack.put(actName, _activity);
}

// Remove Activity
public static void removeActivity(String key) {
    if (Config.screenStack != null && Config.screenStack.size() > 0) {
        Activity _activity = Config.screenStack.get(key);
        if (_activity != null) {
            Config.screenStack.remove(key);
            _activity.finish();
        }
    }
}

用户在setContentView之前添加活动以将其添加到堆栈中.

User add activities before setContentView to add into the stack.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addActivities("DemoActivity", DemoActivity.this)
    setContentView(R.layout.activity_create_feed_post);
}

如果要在应用程序中存在时完成所有活动,则可以 查看此代码.

If you want to finish all activity when you exist from app you can see this code.

这篇关于如何从android back stack删除特定活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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