How about! I commented: Create a service on Android, but when you start the application it closes and removing the service removes that problem.
Here I start my service:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this, sservicio.class);
startService(intent);
Here is the sservice class:
public class sservicio extends Service{
public sservicio() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
Log.d(TAG, "Servicio creado...");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
new CargarDatos().execute("http://www.cybertodo.mx/WebService.php?nombre=" + etNombres.getText().toString() + "&" + "longitud=" + longitud + "&" + "latitud=" + latitud + "&" + "direccion=" + direccion + ". Ciudad: " + cityName + "&" + "equipo=" + datos);
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
Log.d(TAG, "Servicio destruido...");
}
}
This class is in the MainActivity.java. I tried only to send a log with the legend that the service was executed but still closes the app. So I put the service in the AndroidManifest.xml:
<service
android:name=".MainActivity$sservicio"
android:enabled="true"
android:exported="true"></service>