What's the deadliest component on Android?

I am looking for the most appropriate class for the dispatcher for AsyncTasks called from my actions.

I think it might be one of them:

  • subclass of the Application ;
  • subclass Service ;
  • my own static stuff.

As for me, it's easier to implement the third option. But the question is, will it be more "deadly" than a service or application? It is also very interesting which will live longer - an application or a service? My guess is that the app is running until the app process (task from Android perspective) is running.

So basically I need to vary these parameters for their deadly quality, because I would like to rely on the most "static" thing.

UPDATE:

The question was originally asked in 2010 when (1) Android was the new platform for developers and (2) Google documentation was too vague (in some cases even misleading) about the life of application components - loops and the entire lifecycle of the application process.

+2


source to share


1 answer


You should definitely use Service .

The main reason for this is that it Service

has its own documented life cycle , but the application does not. Application

the instance, like any static variable of yours, can be killed by the system at almost any time, you won't get any callback and you won't be able to stop the process. Thus, any unsaved data (all static variables) will be lost.



On the other hand, Service

it cannot be killed by the system silently, the method must be called first onDestroy()

. With a callback like this, you can save your state to some persistent memory (like SharedPreferences, file, database, etc.) and restore that state the next time the application or service starts.

+4


source







All Articles