Voici la class HomeActivity (Tuto sur la creation de service par Benbourahla Nazim)

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
 
package com.tuto.android; 
 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.TextView;
 
public class HomeActivity extends Activity { 
 
 @Override
 public void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.main); 
 
 Button serviceBtn = (Button) findViewById(R.id.serviceBtn); 
 final TextView textAide = (TextView) findViewById(R.id.textAide);
 
 textAide.setText("Affectation OnClick()");
 
 serviceBtn.setOnClickListener( new OnClickListener() 
 { 
 //@Override 
 public void onClick(View actuelView) 
 { 
	 textAide.setText("Démarrage du service");
	 startService(new Intent(HomeActivity.this, ServiceOne.class)); 
 } 
 }); 
 } 
}
Voici le service appelé que j'ai renommé ServiceOne (par rapport a l'original).
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
 
package com.tuto.android; 
 
import android.app.Service; 
import android.content.Context; 
import android.content.Intent; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.os.IBinder; 
import android.widget.Toast; 
 
public class ServiceOne extends Service 
{ 
 private LocationManager locationMgr = null;
 private LocationListener  onLocationChange = new LocationListener() 
 { 
	 //@Override
	 public void onStatusChanged(String provider, int status, Bundle extras) 
	 { 
	 } 
 
	 //@Override
	 public void onProviderEnabled(String provider) 
	 { 
	 } 
 
	 //@Override
	 public void onProviderDisabled(String provider) 
	 { 
	 } 
 
	 //@Override
	 public void onLocationChanged(Location location) 
	 { 
 
		 Double latitude = location.getLatitude(); 
		 Double longitude = location.getLongitude(); 
 
		 Toast.makeText(getBaseContext(), "Voici les coordonnées de votre téléphone : " + latitude + " " + longitude, Toast.LENGTH_LONG).show(); 
	 } 
 }; 
 
 @Override
 public void onCreate() 
 { 
	 Toast.makeText(getBaseContext(), "Creation du service",  Toast.LENGTH_LONG).show(); 
	 locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
	 locationMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0, onLocationChange); 
	 locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0,  onLocationChange); 
	 super.onCreate(); 
	 Toast.makeText(getBaseContext(), "Fin de Creation du service",  Toast.LENGTH_LONG).show(); 
} 
 
 @Override
 public IBinder onBind(Intent arg0) 
 { 
	 return null; 
 } 
 
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) 
 { 
	 return super.onStartCommand(intent, flags, startId); 
 } 
 
 @Override
 public void onDestroy() 
 { 
	 super.onDestroy(); 
	 locationMgr.removeUpdates(onLocationChange);
 }
}
Dans un premier temps j'ai du pour eviter les erreurs de compilation mettre les overrides des methodes surchargées (onStatusChanged, onProviderEnabled, onProviderDisabled, onLocationChanged) de la class LocationListener en commentaire. Par ailleurs, j'ai rajouté des balises pour m'indiquer si les actions se faisaient ou pas.
Quand on click sur le bouton serviceBtn la method Onclick s'execute. Mais le OnCreate de ServiceOne ne s'execute pas.
J'ai fait un copié collé du tuto, et personne d'autre semble affecté par ce probleme, l'erreur doit venir de moi. Mais je la vois pas
Merci de votre aide.