Salut, dans mon application j'utilise un service pour un alarme. Tout marche très bien mais ce que je me demande c'est au niveau des services qui tourne... je m'explique : quand je lance mon application, que je configure une alarme avec mon app je vais ensuite voir dans mes services, aucun processus ou service de mon application n'est entrain de tourner quand je regarde dans mes parametre de mon telephone "service en cours d'exécution". Une fois que mon alarme a en effet sonné que je consulte la notification qu'elle a créé et que je quitte ensuite mon application je vois que dans mes parametre j'ai 1 processus et 1 service de mon application qui sont en cours d'exécution.

Donc voila ma question : pq est ce que le service et processus tourne après que l'alarme se soit enclenché et que j'ai quitté l'application. Est ce que je dois killer le processus ou quelque chose comme ca ? Parce que mine de rien ca consomme :p et je vois pas pourquoi ca consommerais après que l'alarme se soit enclenché :p ...

voila le code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
Alarm alarm = new Alarm(datedate, taskId, true);
 
			Alarm.createAlarm(NoteReminder.this, alarm);
 
........
			PendingIntent pendingIntent = PendingIntent.getService(
					NoteReminder.this, alarmid, myIntent,
					PendingIntent.FLAG_CANCEL_CURRENT);
 
			AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
 
..........
 
			alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis()
					+ diff, pendingIntent);
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 
 
...
 
public class MyAlarmService extends Service {
 
NotificationManager nm;
 
public void onCreate(Bundle savedInstanceState) {
 
Toast myToast = Toast.makeText(this, "blabla", Toast.LENGTH_LONG);
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
 
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
 
myToast.show();
 
//vibre pendant 1 seconde, puis attend 1/2 secondes avant de recommencer (3 fois en tout).
vibrator.vibrate(new long[]{0,1000,500,1000,500,1000}, -1);
}
 
public IBinder onBind(Intent intent) {
 
Toast.makeText(this, "MyAlarmService.onBind()", Toast.LENGTH_LONG).show();
 
return null;
 
}
 
public void onDestroy() {
 
super.onDestroy();
 
Toast.makeText(this, "MyAlarmService.onDestroy()", Toast.LENGTH_LONG).show();
 
}
 
public int onStartCommand(Intent intent, int flags, int startId) {
 
	 Bundle bundle = intent.getExtras();	 
	 long messageid = bundle.getLong("passID", 0);
	 int messageee = (int) messageid;
 
	 String message = TaskReminder.getTaskTitle(MyAlarmService.this, messageid);
	 Toast.makeText(this, message, Toast.LENGTH_LONG).show();
	 Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);	 
 
	final NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
 
notification et le texte qui apparait à la création de la notfication
	final Notification notification = new Notification(R.drawable.notification, "SaS reminder notification", System.currentTimeMillis());  
 
 
	Bundle objetbunble = new Bundle();			
	objetbunble.putLong("passID", messageid);
 
 
	Intent myIntent = new Intent(this, ViewTaskReminder.class);
 
	myIntent.putExtras(objetbunble);
 
 
	final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, myIntent, 0);
 
	final String notificationTitle = "Reminder BIS";
	final String notificationDesc = "This is a reminder from Spot&share reminder !";         
 
	notification.setLatestEventInfo(this, notificationTitle, notificationDesc, pendingIntent);
	notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
   notificationManager.notify(messageee, notification);
 
	 Uri notificationring = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
	 Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notificationring);
	 r.play();
 
	 vibrator.vibrate(new long[]{0,1000,500,1000,500,1000}, -1);
 
	return super.onStartCommand(intent, flags, startId);
}
 
....
 
}
Si quelqu'un a une explication ;-) Merci !