Android的,Intent.FLAG_ACTIVITY_CLEAR_TOP似乎不起作用? [英] Android, Intent.FLAG_ACTIVITY_CLEAR_TOP seems doesn't work?

查看:354
本文介绍了Android的,Intent.FLAG_ACTIVITY_CLEAR_TOP似乎不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的菜单我有一些项目。家是它的,我想我的应用程序的根,每当用户点击它,Android的明确协议栈,然后回到主屏幕中的项目。

In my menu I have some items. Home is an item of it that I want to be root of my application and whenever user clicks on it, Android clear stack and then come back to main screen.

这是我的code:

menu.setOnItemClickedListener(new MenuClickedListener() {
            public void eventOccured(int id) {          

                Intent intent = null;
                switch(id) {
                    case 1: intent = new Intent(context, More.class);           break;
                    case 2: intent = new Intent(context, FavoriteScreen.class); break;
                    case 3: intent = new Intent(context, VideoShowList.class);  break;
                    case 4: intent = new Intent(context, ShoppingList.class);   break;
                    case 5: intent = new Intent(context, MainScreen.class); 
                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            break;                  
                }       

                if(intent != null)
                    context.startActivity(intent); 
            }
        });

菜单工作正常,但似乎标志并不因为从主屏幕上的工作,我去第二个和第三个屏幕,然后我点击菜单首页项,回到主屏幕。现在,当我点击后退按钮,我去第三个屏幕,第二个屏幕和主屏幕。

Menu works fine but it seems flag doesn't work because from Home screen, i go to second and third screen then i click on Home item of menu and come back to home screen. Now, when i click on back button, i go to third screen, second screen and Home screen.

我设计了这个菜单,窗口小部件,以安装它一次,然后重新使用在所有我的屏幕。

I have designed this menu as widget in order to setup it one time and reuse it on all of my screens.

任何建议将是AP preciated。谢谢你。

Any suggestions would be appreciated. Thanks.

推荐答案

尝试使用该 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 的就地intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent intent = new Intent(getApplicationContext(),
            yourActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    startActivity(intent);

这篇关于Android的,Intent.FLAG_ACTIVITY_CLEAR_TOP似乎不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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