有没有办法让每个活动只有一个实例? [英] Is there any way to have one and only one instance of each activity?

查看:89
本文介绍了有没有办法让每个活动只有一个实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现在我的应用程序中,用户可以很嵌套"使用该应用程序时打开的各种活动.

I'm finding that in my application, the user can get quite 'nested' in the various activities that are opened while the user is using the application.

例如:

  1. 主菜单
  2. 对象列表
  3. 对象详细信息
  4. 对象编辑
  5. 对象详细信息
  6. 对象子项详细信息
  7. 对象子级编辑
  8. 对象子项详细信息

现在,当用户按回时,它必须两次通过对象子项详细信息"(相同的对象,当对其进行编辑时,它会返回到详细页面),并且父对象详细信息"也会发生相同的情况

Now, when the user presses back, it has to go through 'Object Child Details' twice (same object, when it is edited it returns to the detailed page), and the same thing happens for the 'Parent Object Details'.

如果活动已经在堆栈中打开,是否可以重用这些活动并将它们重新排序到最前面?我所看到的唯一方法是使用launcher属性进行的活动.我相信我看到了singleTasksingleTop.

Is there a way to reuse activities, if they are already open in the stack, and reorder them to the front? The only way I have seen is on activities with the launcher attribute. I believe I saw singleTask and singleTop.

如果应该使用singleTasksingleTop这两个属性,我应该如何使用它们?当我尝试将它们包括在应用程序中时,没有什么区别.使用startActivity启动意图时,我还需要设置一个标志吗?

If am supposed to be using these two attributes, singleTask and singleTop, how am I supposed to use them? When I tried to include them in the application, it made no difference. Do I also need to set a flag while launching the intent using startActivity?

推荐答案

在清单活动"属性中,您可以将此参数指定为android:launchMode="singleInstance"

in Manifest Activity property you can give this parameter android:launchMode="singleInstance"

在此处详细了解 http://developer.android.com/guide/topics/manifest/activity-element.html

这篇关于有没有办法让每个活动只有一个实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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