2

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;
    }
Hasan
  • 1,243
  • 12
  • 27
  • Edit: I tried to use START_STICKY but this time i am not able to get the same userId value and this causes an error because of returning null value. – Hasan Oct 14 '15 at 00:53
  • Okay i have fixed it by using START_STICKY and for values sharedPreferences.Then i have become able to retrieve the data which i need and use the service effectively. – Hasan Oct 17 '15 at 18:39

0 Answers0