Salve a tutti ragazzi, come potete ben intuire dal titolo non riesco a far partire un Service ci sto provando ma non riesco.
codice service:
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class servizioUp extends Service{
DBapp app;
servizioUp UP;
public void onCreate(){
new Thread(new Runnable(){
public void run(){
Log.i("create", "creato");
aggiorna();
}
}).start();
super.onCreate();
}
public void aggiorna(){
Log.i("Service", "Servizio");
Toast.makeText(getBaseContext(), "Funziona", Toast.LENGTH_LONG).show();
}
public void onStart(Intent intent,int startId){
Toast.makeText(getBaseContext(), "Funziona", Toast.LENGTH_LONG).show();
Log.i("Service", "Service");
Toast.makeText(getBaseContext(), "Funziona", Toast.LENGTH_LONG).show();
}
public int onStartCommand(Intent intent, int flags,int startId){
super.onStartCommand(intent, flags, startId);
Log.i("Service", "Servizio");
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
public IBinder onBind(Intent intent) {
return null;
}
}
codice activity
public class Benvenuto extends Activity implements OnInitListener {
Button button;TextToSpeech tts;
DBUser dbU;
Intent actS;
public void onCreate(Bundle savedInstanceState){
setContentView(R.layout.benevenuto_layout);
super.onCreate(savedInstanceState);
button=(Button)findViewById(R.id.bottone1);
tts=new TextToSpeech(getApplicationContext(), this);
tts.setLanguage(Locale.getDefault());
dbU=new DBUser(getApplicationContext());
startService(new Intent(this, servizioUp.class));
}
public void avanti(View view){
if(dbU.esiste()==false){
Intent changeR=new Intent(this,nomeutente.class);
startActivity(changeR);
finish();
}else{
stopService(new Intent(this, servizioUp.class));
Intent changeM=new Intent(getBaseContext(),MainActivity.class);
startActivity(changeM);
finish();
}
}
public void parla(){
// tts.speak("Ciao benvenuto in Charlie", TextToSpeech.QUEUE_FLUSH, null);
}
@Override
public void onInit(int status) {
parla();
}
}
Manifest:
<service android:name=".servizioUP"
android:enabled="true">
</service>
Grazie mille a tutti coloro che mi daranno una mano