I have a service class in my android app and I want it to catch new entries.If one of the enries is belong to the user I want the service notificate the user.My problem is that after stopping app,service stops and in the working apps section its written 'restarting' for my service and this takes too long time.Here is my code.If anyone could help me I'd be grateful.
Context context;
Timer timer;
int oldEntryCount=0,currentEntryCount=0;
String userId;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
context=getApplicationContext();
Log.d("Service:", "has started to work...");
timer = new Timer();
timer.schedule(new TimerTask() { //her 30 sn de bir bildirimGonder(); metodu çağırılır.
@Override
public void run() {
new GetServiceEntryCount().execute();
//Log.d("Service","called the method...");
}
}, 0, 5000);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent!=null) {
//oldEntryCount = intent.getIntExtra("currentEntryCount", oldEntryCount);
//currentEntryCount=oldEntryCount;
userId = intent.getStringExtra("id");
Log.d("ServiceVariables:", "ENTRYCOUNT:" + oldEntryCount + "USERID:" + userId);
startId++;
}
Log.d("SERVICE->", "flags:" + flags + " startId:" + startId);
return START_REDELIVER_INTENT;
//return START_STICKY;
}