Sto tentando di creare un servizio che gestirà l'I/O dei file in background. Le attività che aggiornano i dati si collegheranno al servizio e chiameranno i metodi del servizio per eseguire l'I/O. Sto usando la documentazione di Android per la guida.Il servizio Android non viene mai avviato - onStartCommand() non chiamato
Tuttavia, il mio servizio sembra non voler iniziare. Nel metodo onCreate() della mia attività, ho:
Intent smsIntent = new Intent(this, SurveyManagerService.class);
String surveyFilename = getIntent().getStringExtra("surveyFilename");
System.out.println(startService(smsIntent)); //testing if it starts
SurveyManagerServiceConnection connection = new SurveyManagerServiceConnection();
sms = connection.getSurveyManagerService();
Alla linea 3 LogCat emette un oggetto ComponentInfo, quindi sembrerebbe che il servizio è stato creato; tuttavia, sms è nullo. Inoltre, il metodo SurveyManagerService onStartCommand() non sembra mai di essere chiamato:
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
System.out.println("starting service");
Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
openSurveyFromIntent(intent);
return START_REDELIVER_INTENT;
}
non ho mai vedere qualsiasi uscita "Servizio di partenza" in LogCat, né apparire il Toast.
Il mio servizio è dichiarato nel mio manifestano come:
<service android:name=".SurveyManagerService" android:exported="false" android:enabled="true">
</service>
mi sto perdendo qualcosa di ovvio? Fammi sapere quali altre informazioni dovrei fornire per diagnosticare il problema.
Forse il vostro servizio si blocca ripetutamente? – Reno
Come posso verificare se si verifica un arresto anomalo prima della prima riga di onStartCommand()? Grazie. Ho dimenticato di dire che il metodo onCreate() ha anche un test System.out.println, che non viene mai chiamato. – Spinner