public void onDestroy() { if (debug) Log.i(tag, "onDestroy()"); isRunning = false; db.updateDataEventPositionEnd(this.deID, DBHelper.DATA_EVENT_STOPPED); sensorManager.unregisterListener(this); // Tell the user we stopped. Toast.makeText(this, "Sensor Collection Service Stopped", Toast.LENGTH_SHORT).show(); if (!db.addDataItems(vectorList, deID, accuracy)) Toast.makeText(this, "Data Was Not Saved Successfully!", Toast.LENGTH_SHORT).show(); else Toast.makeText(this, "Data Saved Successfully!", Toast.LENGTH_SHORT).show(); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (debug) Log.i(tag, "onStartCommand()"); Bundle extras = intent.getExtras(); this.uID = extras.getLong("uID"); this.deID = extras.getLong("deID"); db = new DBHelper(this); db.updateDataEventPositionEnd(this.deID, DBHelper.DATA_EVENT_RUNNING); Toast.makeText(this, "Service Collection Service started!", Toast.LENGTH_SHORT).show(); // We want this service to continue running until it is explicitly // stopped, so return sticky. // return START_NOT_STICKY; return START_STICKY; }