Android:从堆栈中删除活动 [英] Android: remove activity from stack
问题描述
我的应用程序后端具有数据库树结构. 基本上看起来像这样:
I have a database tree structure in the backend of my application. It basically looks like the following:
List
|- View
我编写了将视图转换为显示视图的列表的功能.显示在这里:
I wrote the functionality to transform a View to a List displaying the View. Shown in here:
List
|- List
|- View
当触发toList()
函数时,应用程序应重建数据库中的结构,并切换到显示列表内容的新列表活动.
When triggering the toList()
function the Application should rebuild the structure in the database, and switch to the new List Activity displaying the list content.
以上所有作品,除了一件事:
All of the above works, except one thing:
切换到新的列表活动时,应从堆栈中删除以前的视图,以便在按后退"按钮时保持顺序.
When switching to the new List Activity the previous View should be removed from the stack in order to keep the order when pressing the 'back' button.
我尝试了以下意图:
Intent i = new Intent(ViewActivity.this, ListActivity.class);
// new_item is a DTO containing the needed id to create the List activity
i.putExtra("selected_item", _new_item);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PostActivity.this.startActivity(i);
以及:
Intent i = new Intent(ViewActivity.this, ListActivity.class);
// new_item is a DTO containing the needed id to create the List activity
i.putExtra("selected_item", _new_item);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
PostActivity.this.startActivity(i);
两者均无法正常工作.
是否还有其他可能出于上述目的使用finish()
的方法?
我显然不想为得到结果而开始活动.
Is there any other method of maybe using finish()
with the above intent?
I explicitely don't want to start the activity for a result.
推荐答案
只需在代码末尾添加finish()并删除标志,这将破坏ViewActivity并将其从堆栈中删除!
Just add a finish() at end of your code and remove the flags, this will destroy the ViewActivity and it will be removed from your stack!
Intent i = new Intent(ViewActivity.this, ListActivity.class);
// new_item is a DTO containing the needed id to create the List activity
i.putExtra("selected_item", _new_item);
PostActivity.this.startActivity(i);
finish();
这篇关于Android:从堆栈中删除活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!