My service class not running in background i have followed the sample tutorial, dont what is the issue and why its not running?
This is my Service class
public class Services extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
Log.d("OnBind", "OnBind");
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
Log.d("OnCreate", "OnCreate");
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
Log.d("OnStart", "OnStart");
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
}
My Menifest
<service
android:name=".Services"
android:enabled="true" >
</service>
MyActivity to call the services
startService(new Intent(getApplicationContext(), Services.class));
Kindly look it out my coding and help me to run the app properly,
Thanks in Advance.
Check by providing the whole name of services class like com.example.Services
rather than .Services
in your manifest file.
For continiously running the service, do the following :
public class YourServiceName extends Service {
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onStart(Intent i, int startId) {
this.test.run();
this.stopSelf();
}
public Runnable test= new Runnable() {
public void run() {
// Do something
}
};
}
The AlarmManager that starts it:
Intent testService = new Intent(this, YourServiceName .class);
PendingIntent pitestService = PendingIntent.getService(this, 0,testService,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pitestService);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000, pitestService);
Hope this helps.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments