我在我的Android应用程序中有一个服务类,我希望它能够捕获新条目。如果其中一个enries属于用户,我希望服务通知用户。我的问题是停止应用程序后,服务停止并且在工作应用程序部分,它的书面重新启动'为了我的服务,这需要很长时间。这是我的代码。如果有人能帮助我,我会感激不尽。
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;
}