The class Aplication
is like a Singleton, is one for each application Android
. But it was not designed to perform background tasks, but rather to store information on the application.
As it says in the javadoc:
Application
Base class to maintain application status. You can provide your own implementation by specifying your Androidmanifest.xml’s in the tag, this causes your class to be instantiated when your application/package process is created.
http://developer.android.com/reference/android/app/Application.html
As for the Asynctask
Asynctask facilitates and enables proper use of the UI Thread( A Thread that draws on the screen). This class allows you to perform background operations and publish results on the screen without having to manipulate Threads and/or Handlers.
Soon AsyncTask
does background operations to show somewhere, and Application
serves to save application states.
Neither of these matches exactly with your need to run an application that is always connected to the server.
For this you need to use another structure, which is the Service
.
You can get more information about services in the official documentation:
http://developer.android.com/guide/components/services.html
As far as I know, the class
Application
represents your application and does not offer any feature to maintain connection with a server. You do not meanService
?– Piovezan
Supposedly we can have several 'Application' in our App. I did not understand very well this concept applied to programming in Android is why my doubt lies in Application or Async Task.
– urb
Incorrect. Where you read this?
Application
should be one per app (theAndroidManifest.xml
only allows you to register an application subclass in the attributeandroid:name
of the element<application>
, when that subclass exists). Again, you don’t want to sayService
?– Piovezan
I use and recommend the Volley library that is recommended by Google. https://developer.android.com/training/volley/simple.html I make a single instance of it as an Application. From a research on.
– Rafael Silva