饲养活动还活着 [英] Keeping activity alive

查看:139
本文介绍了饲养活动还活着的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列的活动,在我的应用程序,开始活动A,后由B,C,D和E。活动A,B,C和D是透明的活动(透明主题),而E是不透明的。

要求是活动A应该不会完蛋。我读通过博客 HTTP:// WWW .skill-guru.com /博客/ 2011/01/13 / Android的活性生命周期/这指出,

  1. 如果活动已经失去焦点,但仍清晰可见(即,一个新的 非全尺寸或透明的活动都集中在顶部您 活性),它被暂停。
  2. 如果活动被另一个活动完全遮蔽,这是 停了下来。

活动的onStop()A不叫,直到用户浏览到活动D,然而当活动E被调用的叫法。

反正是有,我们可以保持活动在活动栈A运行?它是一个很好的解决方案,以保持活动的静态引用的应用对象,以便框架不杀呢?什么precautions我可以让A不杀?有没有一种方法,我可以得到一个通知,如果这被杀害的框架,这样我可以重新创建它?

解决方案
  

要求是活动A不应该结束了。

这是活动是通过调用完成(完)。这通常发生在用户presses BACK按钮。

  

活动的onStop()A不叫,直到用户浏览到活动D,然而当活动E被调用的叫法。

正确的。

  

反正是有,我们可以保持活动在活动栈A运行?

它的的在活动栈(为跑任何合理的定义)运行,直到您拨打的时间完成(),系统用户presses BACK,或者过程终止。 的onStop()有没有影响。

  

它是一个很好的解决方案,以保持活动的静态引用的应用对象,以便框架不杀呢?

没有,因为它不会帮助。该活动将保留在内存中,直至您拨打完成(),用户presses回来,还是终止处理。

  

什么precautions我可以让A不杀?

不要叫完成()

  

有没有一种方法,我可以得到一个通知,如果这被杀害的框架,这样我可以重新创建它?

您的活动将被称为的onDestroy()如果它完成。此,如果处理终止可能或可能不发生,这取决于触发时刻的终止和系统的状态。

I have a series of activities in my application which starts with Activity "A" and followed by "B", "C" , "D" and "E". Activity "A","B","C" and "D" are transparent activities (transparent theme) while "E" is opaque.

The requirement is the Activity "A" should not be finished. I read through a blog http://www.skill-guru.com/blog/2011/01/13/android-activity-life-cycle/ which states that

  1. If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused.
  2. If an activity is completely obscured by another activity, it is stopped.

The onStop() of Activity "A" is not called till the user browses to Activity "D" however it is called when Activity "E" is invoked.

Is there anyway that we can keep the Activity "A" running in the Activity stack? Is it a good solution to keep a static reference of the Activity in a Application object so that framework does not kill it ? What precautions can i take so that "A" is not killed? Is there a way that i can get a notification if this gets killed by framework so that i can recreate it ?

解决方案

The requirement is the Activity "A" should not be finished.

An activity is finished via a call to finish(). This normally happens when the user presses the BACK button.

The onStop() of Activity "A" is not called till the user browses to Activity "D" however it is called when Activity "E" is invoked.

Correct.

Is there anyway that we can keep the Activity "A" running in the Activity stack?

It is "running" in the activity stack (for any reasonable definition of "running"), until such time as you call finish(), the user presses BACK, or the process is terminated. onStop() has no impact on that.

Is it a good solution to keep a static reference of the Activity in a Application object so that framework does not kill it ?

No, because it is not going to help. The activity will remain in memory until such time as you call finish(), the user presses BACK, or the process is terminated.

What precautions can i take so that "A" is not killed?

Do not call finish().

Is there a way that i can get a notification if this gets killed by framework so that i can recreate it ?

Your activity will be called with onDestroy() if it is finished. This may or may not occur if the process is terminated, depending on what triggered the termination and the state of the system at that time.

这篇关于饲养活动还活着的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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