当前位置: 动力学知识库 > 问答 > 编程问答 >

Preventing empty app process under Android

问题描述:

I am porting an existing Windows 8 / iOS app to Android.

Of course, I want to re-use as much of the program logic / control flow as possible.

Unfortunately, Android has this strange concept of Activities.

(I only use one single activity because the app is a game.)

The problem I have is the following:

  • Static variables are not bound to the activity lifetime but to the process lifetime.
  • My activity can be destroyed while the process is still alive. (be it through configuration change or due to low memory)
  • But I have to be sure that a newly created activity gets "fresh" static variables.

I could solve the problem by

  • preventing activity restarts due to configuration changes (that's fine with be because I do not use layouts or size-dependent resources)

AND at the same time

  • assuring that when the activity is destroyed (e.g. user switches to another app, memory low), the whole process will be destroyed, too.

The later one is my question: How do I make sure that the app process is killed whenever there are no activities alive? (In my understanding, it is not impossible, unfortunately, that empty processes exist)

分享给朋友:
您可能感兴趣的文章:
随机阅读: