Android的历史堆栈无一明确堆栈、明确、历史、Android

2023-09-12 22:24:41 作者:妳的愛丶我已經戒不掉。

我有一些活动likr

I have a some activities likr

A-> Splash Screen
B-> Home Screen
C-> a List activity
D-> a View activty
E-> a List activity
F-> a View activty

Normaly应用程序开始A - > B

Normaly application start with A -> B

然后用户选择列表的活动

Then user select a list activity

然后用户从列表中选择活动视图。

then user select a view from list activity.

我的问题是清算activty堆栈。

my problem is clearing activty stack.

我的应用程序会跳转列表或查看活动的活动(与facefook风格的导航)

my application will jump list or view activity to an activity (with facefook style navigation)

例如用户选择一个列表活动℃,比选择查看活动D.在帽子点,用户可以跳转到acitivty E.当活动E,如果用户preSSØ后退按钮,用户进入活动D.

For example user select a list activity C and than select view activity D. at hat point user can jump to acitivty E. When in activity E, if user press o back button, user go to the activity D.

我想要去的activty B(主页)。

I want that to go to the activty B(Home).

我的意思是我想清楚了活动stact没有回家的活动。

I mean ı want to clear activity stact without home activity.

我该怎么办呢?

索里的awasome英语。

sory for awasome English.

感谢。

推荐答案

您可以拦截后退按钮preSS像这样:

You can intercept the back button press like so:

@Override
public void onBackPressed() {
    // You want to start B Activity
    Intent a = new Intent(this, B.class);

    // But you dont want it on top of E.
    a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    // Launching this will now remove every activity on top of B and bring B to front, not! relaunch it.
    startActivity(a);
}

您可能要检查出 Android的意图标志和任务和返回堆栈文档。

有一个愉快的一天!

编辑:

如果您要关闭您的应用程序时,背部是pressed:

If you want to close your app when back is pressed:

@Override
public void onBackPressed() {
    moveTaskToBack(true);
}