Services sous android Leçon 1
By admin • nov 20th, 2009 • Category: TutorialsA la différence des activités qui présentent une interface graphique a l’utilisateur, les services s’exécutent en tache de fond
Une fois le service crée il faut l’enregistrer aupres de l’application
Pour démarrer un service on fait appel a startService();
Si le service requiert des permissions que l’application ne possède pas alors cet appel lancera une exception
public class MyService extends Service { @Override public void onCreate(){ // What to do when service is created } @Override public IBinder onBind(Intent intent){ // Replace with service binding implementation } @Override public void onStart(){ // Action to perform when service starts } } // techniques pour demarrer un service // implicite startService(new Intent(MyService.MY_ACTION)); // Explicite startService(new Intent(this,MYService.class)); // stop service en appelant la methode stopService et en lui passant // le service a stopper stopService(new Intent(this,service.getClass())); // appel explicite try { Class serviceClass = Class.forName(service.getClassName()); stopService(new Intent(this,serviceClass)); } catch (ClassNotFoundException e){ }
A voir aussi:
admin is
Email this author | All posts by admin
