I am trying to replace a code that I did using thead by services, but when I create the service it does not start (it does not start any service method) and searching the net I saw some solutions that said it could be in "manifest.xml "but the changes I made did not resolve the issue.
My question is: Where am I going wrong?
The manifesto:
<permission android:name="android.permission.FLASHLIGHT"
android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
android:protectionLevel="normal" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Metronome.Theme" >
<activity
android:name=".view.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Metronome.Main.Theme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<service android:name=".Compasso"/>
</activity>
<activity
android:name=".view.ConfiguracoesActivity"
android:label="@string/title_activity_configuracoes"
android:screenOrientation="portrait" >
</activity>
</application>
This is the method in the activity that I try to start the service:
public void executar(){
FrontConversor conversor = new FrontConversor();
conversor.setVibracao(true);
conversor.setFlash(false);
conversor.setTempoMinutos(npTimer.getValue());
conversor.setFrequenciaBPM(npBPM.getValue());
conversor.setQuantidadeBatidas(npQntBatidas.getValue());
conversor.createSomById(getIdSom(), this);
conversor.createFiguraRitmicaById(npValorBase.getValue());
//executer.preExecuter(conversor, this); // preparar
startService(new Intent(this,Compasso.class)); // executar
}
And this is a part of the class that extends service (class compass):
public class Compasso extends Service{
...
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("MARK","Service iniciado");
double frequenciaSegundos = this.conversorBPM(this.frequenciaBPM); // 2bps
double Delay = 1000 / frequenciaSegundos; // 0.5s
int tempoMiliSegundos = (this.tempoMinutos * 60 * 1000); // (60000 milisegundos)
double quantidadeCiclo = tempoMiliSegundos / (this.batidasMaximo * Delay);
this.stopNow = false;
try {
// Iniciando ciclo de batidas
loopSound(Delay, quantidadeCiclo);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
this.stopMetronomo();
}
return START_STICKY;
}
...
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
So I think it should return when the service starts will be an error (nullpointerException) but not even an error it returns.
Thank you in advance.