整理(或访问)在Android中的特定活动Android

2023-09-04 06:32:38 作者:灵魂摆渡人

由于活动是由用户打开,他们叠起来的视图堆栈。 并且随着用户通过任何手段完成的活动,它冒出来的观点栈。

As Activities are opened by the user, they're stacked up on the view stack. and as the user finishes an Activity by any means, it is popped out of the view stack.

现在,我有一种情况,用户打开应用程序的主屏幕,并先后开了多个活动,在主屏幕的顶部。在每一个活动中,有一个控制,让用户再次看到主屏幕。

Now, I have a situation where the user has opened the app's home screen, and has successively opened multiple activities, on top of the home screen. In each activity, there's a control which lets the user see the home screen again.

由于我能想到的,可以有两种方法可以得到这样的:

As i can think, there can be two approaches to get this:

在该控件的preSS,从视图栈底弹出的主屏幕,推动它在它的顶部。 由于控制是pressed,开始每次弹出当前屏幕,直到主屏幕成为当前屏幕。

我知道有一些方法在Android中至少做一本,或者是这样的。 我只是不记得具体是什么。

I know there's some way in Android to do at least one of this, or something like this. I just can't remember what was it.

请帮我选的更好的办法,让我知道的方式(在code,特别是)来做到这一点。

Please help me choose the better approach, and let me know the way (the code, specifically) to do it.

多谢:)

(请编辑标题/文本,如果它是不恰当的)

(Please edit the title/text if it isn't appropriate)

推荐答案

尝试这样的事情

Intent i = new Intent();
    i.putExtra(EXTRA_KEY_ARTIST, id);
    i.setClass(this, ArtistActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(i);

这就是当你设定的FLAG_ACTIVITY_SINGLE_TOP属性它不会开始一个新的活动,但会显示您的行为如果不被破坏尚未intially创建,

That's all when you set the the FLAG_ACTIVITY_SINGLE_TOP property it wont start a new activity but will show your activity intially created if its not destroyed yet,

但是,如果你的活动是开始活动,那么你可以把它像这样

But if your activity is the starting activity then you can put it like this

 <activity
    android:name=".ArtistActivity"
    android:label="Artist"
    android:launchMode="singleTop">
</activity>