gpt4 book ai didi

android - 从堆栈返回到特定 Activity

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:17:42 25 4
gpt4 key购买 nike

我正在尝试做一些类似文件管理器的事情。在操作栏中,我想像在“google drive”应用程序中那样进行文件夹导航。我需要创建方法,它可以从末尾按数字或类似的方法转到上一个 Activity 。

例子:

So if I have stack: [1] -> [2] -> [3] -> [4] -> [5]

And I need go to second: so I need delete [3], [4], and [5] from stack and go to [2].

All activities is one class ContentActivity.java.

这怎么可能?

更新:

我如何开始 Activity 的一些代码:

public class ContentActivity extends Activity implements AdapterView.OnItemClickListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);

Intent intent = getIntent();
String folderToOpen = intent.getStringExtra("folderName");
fillList(folderToOpen);
}


@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
...
Intent intent = new Intent(ContentList.this, ContentList.class);
intent.putExtra("folderName", item.getName());
startActivity(intent);
}
}

最佳答案

假设 Activity2 是您要进行的第二个 Activity ,

试试这个:

Intent intent = new Intent(this,Activity2.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

根据 Android Documentation关于 FLAG_ACTIVITY_CLEAR_TOP

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

关于android - 从堆栈返回到特定 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23826483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com