Hello my fellow programmers :)
I call the function waitRunnable(int seconds, int startId) 4 times every time I click a button in my application. So waitRunnable() should just wait a variable amount of time and the time is set by a parameter seconds. But they run all at the same time so if the longest waitRunnable gets 10 seconds to wait and the other 3 waitRunnables wait less time then all 4 waitRunnables finish after 10 seconds but the first one should finish and just then the second one should be started so the total amount of time would be the sum of all parameters. I hope this is not to bad explained.
In love your jason <3 Thx for help :)
package com.example.Uebung10;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.os.Handler;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
* Created by Jason on 14.01.2016.
*/
public class MyService extends Service {
final String LOG_TAG = "myServiceLogs";
Handler h = new Handler();
List<String> finishedTasksInTheLast60Sec = new ArrayList<>();
ExecutorService es;
Runnable r = new Runnable() {
#Override
public void run() {
sendBroadcast(finishedTasksInTheLast60Sec);
h.postDelayed(this, 60000);
finishedTasksInTheLast60Sec = new ArrayList<>();
}
};
private void waitRunnable(int seconds, int startId) {
h.postDelayed(new Runnable() {
#Override
public void run() {
finishedTasksInTheLast60Sec.add("Finished Task: MyRun#" + startId);
Log.d(LOG_TAG, "MyRun#" + startId + " end");
}
}, TimeUnit.SECONDS.toMillis(seconds));
}
private void sendBroadcast(List<String> finishedTasks) {
Intent intent = new Intent("myServiceUpdate");
intent.putExtra("finishedTasks", (ArrayList<String>)finishedTasks);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
public void onCreate() {
super.onCreate();
Log.d(LOG_TAG, "MyService onCreate");
es = Executors.newFixedThreadPool(1);
h.postDelayed(r, 60000);
}
public void onDestroy() {
super.onDestroy();
h.removeCallbacks(r);
Log.d(LOG_TAG, "MyService onDestroy ");
}
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(LOG_TAG, "MyService onStartCommand");
readFlags(flags);
int time = intent.getIntExtra("time", 1);
if (time != -1) {
MyRun mr = new MyRun(time, startId);
es.execute(mr);
} else stopSelf();
return START_NOT_STICKY;
//return START_STICKY;
//return START_REDELIVER_INTENT;
}
#Override
public IBinder onBind(Intent intent) {
Log.d(LOG_TAG, "onBind");
return null;
}
void readFlags(int flags) {
if ((flags & START_FLAG_REDELIVERY) == START_FLAG_REDELIVERY)
Log.d(LOG_TAG, "START_FLAG_REDELIVERY");
if ((flags & START_FLAG_RETRY) == START_FLAG_RETRY)
Log.d(LOG_TAG, "START_FLAG_RETRY");
}
class MyRun implements Runnable {
int time;
int startId;
public MyRun(int time, int startId) {
this.time = time;
this.startId = startId;
Log.d(LOG_TAG, "MyRun#" + startId + " create");
}
#Override
public void run() {
Log.d(LOG_TAG, "MyRun#" + startId + " start, time = " + time);
waitRunnable(time, startId);
}
}
}
You can use an ExecutorService to store a queue of Runnables and perform them one at a time. Call ExecutorService#submit to add a Runnable to the queue.
http://developer.android.com/reference/java/util/concurrent/ExecutorService.html
Related
This code is on a wearable. I need to create a service with custom constructor (I need to pass in another context). So I created and started the service this way:
Update 2 this part is in onCreate() of the calling activity (WearActivity).
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
HeartRateMonitorService service = new HeartRateMonitorService(WearActivity.this);
service.onCreate();
service.onStartCommand(null,0,123);
}
}, 5000);
Then in the onStartCommand function, I posted a delay Runnable to stop the service by stopSelf.
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
int superResult = super.onStartCommand(intent, flags, startId);
//...other code
Handler handler = new Handler();
handler.postDelayed( stopServiceRunnable
, EXPIRY_TIME_IN_MILLIS);
return START_NOT_STICKY;
}
Runnable stopServiceRunnable = new Runnable() {
#Override
public void run() {
Log.d(TAG, "calling stopSelf()");
stopSelf();
}
};
The code did jump to inside the Runnable (by printing out the log line), however, it didn't jump to onDestroy(). Also, other tasks in the service keep performing and printing out logs (it is a heart rate monitoring service).
Any idea? Thanks.
Update: full source code file as required:
package com.marctan.hrmtest;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.wearable.MessageApi;
import com.google.android.gms.wearable.Node;
import com.google.android.gms.wearable.NodeApi;
import com.google.android.gms.wearable.Wearable;
import com.google.android.gms.wearable.WearableStatusCodes;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentLinkedQueue;
public class HeartRateMonitorService extends Service implements SensorEventListener {
private static final String TAG = "HRService";
private Sensor mHeartRateSensor;
private SensorManager mSensorManager;
// private CountDownLatch latch;
private static final int SENSOR_TYPE_HEARTRATE = 65562;
private int mStartId;
private static final String PATH = "MyHeart";
TimerTask timerTask;
private long mStartTime;
public static final long EXPIRY_TIME_IN_MILLIS = TimeUtils.InMillis.SECOND *20;
private static final long INTERVAL_TO_CHECK_CONNECTION_MILLIS = 3000 ;
GoogleApiClient googleApiClient;
Context mBaseConext;
private Timer mTimer;
ConcurrentLinkedQueue<HeartRate> queue;
public HeartRateMonitorService(Context context){
super();
mBaseConext = context;
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
attachBaseContext(mBaseConext);
queue = new ConcurrentLinkedQueue<HeartRate>();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
int superResult = super.onStartCommand(intent, flags, startId);
mStartId = startId;
Log.d(TAG, "prepare to call getSystemService");
mSensorManager = ((SensorManager)mBaseConext.getSystemService(SENSOR_SERVICE));
Log.d(TAG, "after calling getSystemService");
mHeartRateSensor = mSensorManager.getDefaultSensor(SENSOR_TYPE_HEARTRATE); // using Sensor Lib2 (Samsung Gear Live)
mSensorManager.registerListener(HeartRateMonitorService.this, mHeartRateSensor, 3);
mStartTime = System.currentTimeMillis();
googleApiClient = new GoogleApiClient.Builder(HeartRateMonitorService.this)
.addApi(Wearable.API)
.build();
googleApiClient.connect();
startActiveStateCheckingTimer();
Handler handler = new Handler();
handler.postDelayed( stopServiceRunnable
, EXPIRY_TIME_IN_MILLIS);
return START_NOT_STICKY;
}
/***/
private void startActiveStateCheckingTimer() {
if (mTimer == null) {
mTimer = new Timer();
timerTask = new CheckTask();
mTimer.scheduleAtFixedRate(timerTask, 0,
INTERVAL_TO_CHECK_CONNECTION_MILLIS);
}
}
Runnable stopServiceRunnable = new Runnable() {
#Override
public void run() {
mSensorManager.unregisterListener(HeartRateMonitorService.this);
Log.d(TAG, "calling stopSelf()");
stopSelf();
}
};
private class CheckTask extends TimerTask{
int localCount=0;
#Override
public void run() {
Log.d("SHORT_IN","count: "+ localCount );
fireMessageSimple();
localCount++;
}
}
public static class HeartRate {
private final int accuracy;
final int rate;
final long signature;
public HeartRate(int rate, long _sign, int accuracy) {
this.rate = rate;
this.signature= _sign;
this.accuracy = accuracy;
}
}
#Override
public void onSensorChanged(SensorEvent sensorEvent) {
//should get the time outside the queuing task to be precise
long timeStampMillis = System.currentTimeMillis();
QueuingTask task = new QueuingTask(queue,timeStampMillis, sensorEvent);
task.execute();
}
private void fireMessageSimple() {
// Send the RPC
PendingResult<NodeApi.GetConnectedNodesResult> nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient);
nodes.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
#Override
public void onResult(NodeApi.GetConnectedNodesResult result) {
for (int i = 0; i < result.getNodes().size(); i++) {
Node node = result.getNodes().get(i);
String nName = node.getDisplayName();
String nId = node.getId();
Log.d(TAG, "Node name and ID: " + nName + " | " + nId);
byte [] myBytes;
StringBuilder sBuidler = new StringBuilder();
Iterator<HeartRate> iter = queue.iterator();
int count=0;
while (iter.hasNext() && count <100 ){
HeartRate rate = iter.next();
sBuidler.append(rate.signature).append(",").append(rate.accuracy).append(",").append(rate.rate).append("\n");
iter.remove();
count++;
}
myBytes = sBuidler.toString().getBytes();
PendingResult<MessageApi.SendMessageResult> messageResult = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(),
PATH, myBytes);
messageResult.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
#Override
public void onResult(MessageApi.SendMessageResult sendMessageResult) {
Status status = sendMessageResult.getStatus();
Log.d(TAG, "Status: " + status.toString());
if (status.getStatusCode() == WearableStatusCodes.SUCCESS) {
Log.d(TAG, "SENT SUCCESSFULLY !!!!!!!!!!!!!");
}
}
});
}
}
});
}
#Override
public void onAccuracyChanged(Sensor sensor, int i) {
Log.d(TAG, "accuracy changed: " + i);
}
#Override
public void onDestroy() {
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
Log.d(TAG, "calling onDestroy");
super.onDestroy();
}
}
Just an hint, instead of use a runnable try to use an asyncTask as follow
public class StopServiceTask extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(final Void... params) {
try {
Thread.sleep(EXPIRY_TIME_IN_MILLIS);
} catch (final InterruptedException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(final Void result) {
Log.d(TAG, "calling stopSelf()");
stopSelf();
}
}
and call it where you are currently running your runnable
new StopServiceTask()
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
Let me know if this work.
I know the local service runs in the UI thread of the main process, the same as activity.
According to this principle,it shouldn't work immediately when I do something in an activity, if something time-consuming is running in service.
But the example below isn't so.
Who can tell me the truth?
Much appreciate!
package com.example.testservice;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
public class MyService extends Service {
private static final String TAG = "LocalService";
private MyService.LocalBinder binder = new MyService.LocalBinder();
public class LocalBinder extends Binder {
MyService getService() {
return MyService.this;
}
}
#Override
public IBinder onBind(Intent intent) {
return binder;
}
#Override
public void onCreate() {
Log.i(TAG, "onCreate");
super.onCreate();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand");
//I do something time-consuming in here.
for (int i = 1; i <= 10; i++) {
Log.i(TAG, "Name:" + Thread.currentThread().getName()
+ ".Service i:" + i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return START_STICKY;
}
#Override
public void onDestroy() {
Log.i(TAG, "onDestroy");
super.onDestroy();
}
#Override
public boolean onUnbind(Intent intent) {
Log.i(TAG, "onUnbind!");
return super.onUnbind(intent);
}
}
Below is the Activity code:
#Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.btnTimeConsuming:
for(int i = 1;i <= 10; i ++)
{
Log.i(TAG, "Name:" + Thread.currentThread().getName() + ".Activity i:" + i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
break;
case R.id.btnStartService:
startService(intent);
break;
default:
break;
}
}
When I click the Button "R.id.btnStartService",the I click the Button "R.id.btnTimeConsuming"
It print the below Log.
The task in Service and the task in Service is complicating. Why?
I am currently working with an Android content provider that i have created i use the query methode in a service because i have to update my result every 2 second my probleme is i want to get the last row in my databases, I put the sursor to the last position but every time his getting me all the data that he found in the database.
this is the service that I developed:
package fr.esigetel.echange.service;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import fr.esigetel.mediatag.cp.WifiProvider;
public class informationService extends Service {
Timer mTimer;
private Handler mHandler = new Handler() {
#Override
public void handleMessage(Message msg) {
returnContentProvider();
}
};
#Override
public void onCreate() {
super.onCreate();
mTimer = new Timer();
Log.d("onCreate informationService", "onCreate informationService");
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
mTimer.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
mHandler.sendEmptyMessage(0);
}
}, 0, 5000);
return super.onStartCommand(intent, flags, startId);
}
#Override
public void onDestroy() {
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}
if (mHandler != null) {
mHandler = null;
}
super.onDestroy();
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
public informationService() {
}
private void returnContentProvider() {
Uri myuri = Uri.parse("content://fr.esigetel.mediatag.cp/maxdata");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(myuri, null, null, null, null);
int idRech = c.getColumnIndex(WifiProvider.MAX_COL_ID);
int nameap = c.getColumnIndex(WifiProvider.MAX_COL_APName);
int adressemac = c.getColumnIndex(WifiProvider.MAX_COL_AdresseMac);
int rssi = c.getColumnIndex(WifiProvider.MAX_COL_RSSI);
int frequence = c.getColumnIndex(WifiProvider.MAX_COL_Freq);
int daterech = c.getColumnIndex(WifiProvider.MAX_Date);
c.moveToLast();
while (c.moveToPrevious()) {
int id = c.getInt(idRech);
String name = c.getString(nameap);
String mac = c.getString(adressemac);
int Rssi = c.getInt(rssi);
int Freq = c.getInt(frequence);
int Daterech = c.getInt(daterech);
try {
} catch (Exception e) {
System.out.println(e.getMessage());
}
Log.d("aaaaaa", name);
}
c.close();
}
How could i request only the last row of my database? this methode alway give me the whole data.
Cursor c = cr.query(myuri, null, null, null, null);
c.moveToLast();
Now Cursor Is At Last Possition And get The Last Record Data
int idRech = c.getColumnIndex(WifiProvider.MAX_COL_ID);
int nameap = c.getColumnIndex(WifiProvider.MAX_COL_APName);
int adressemac = c.getColumnIndex(WifiProvider.MAX_COL_AdresseMac);
int rssi = c.getColumnIndex(WifiProvider.MAX_COL_RSSI);
int frequence = c.getColumnIndex(WifiProvider.MAX_COL_Freq);
int daterech = c.getColumnIndex(WifiProvider.MAX_Date);
I want to stop my service went it complete its tasks. but service wont be stopped I override the onDestroy() but it dose not work. When service stops it will start a new activity.below is my code
DataService.java
package com.remote.synchronizer.haris;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.http.NameValuePair;
import android.app.Service;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class DataService extends Service {
boolean wifi,edge;
private Timer timer= new Timer();
SQLiteDatabase db;
String un,shop,city,date,order;
private SQLiteAdapter mySQLiteAdapter;
#Override
public void onCreate(){
super.onCreate();
mySQLiteAdapter = new SQLiteAdapter(this);
// this.stopSelf();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
final Handler mHandler = new Handler();
new Thread(new Runnable(){
#Override
public void run() {
Log.e("Service Started", "Successful");
while(true){
try{
Thread.sleep(10000);
mHandler.post(new Runnable() {
#Override
public void run() {
//Checking network connectivity
wifi=NetworkInfo.Wifi(DataService.this);
edge=NetworkInfo.EDGE(DataService.this);
if(wifi==true||edge==true)
{
int count=mySQLiteAdapter.getCCount();
int counter=0;
if(mySQLiteAdapter.getCCount()>0){
while(counter<count){
Log.e("Service Network", "Network is online");
int id=mySQLiteAdapter.getID();
List<NameValuePair> contacts=new ArrayList<NameValuePair>();
contacts=mySQLiteAdapter.getSingleRecord(id);
String url="http://10.0.2.2:3325/Product/Create?";
int response = 0;
try
{
response = CustomHttpClient.executeHttpPost(url, contacts);
if(response==200){
mySQLiteAdapter.delete_byID(id);
Log.e("Data Sent", "Response 200");
counter++;
}
else{
Log.e("Service Data", "Faield to upload data" );
}
}
catch (Exception e)
{
Log.e("Data Sending Error", e.toString());
e.printStackTrace();
}
}
}
//
Thread.currentThread().interrupt();
}
else
{
Log.e("Service Network", "Network is offline");
}
}
});
}
catch (InterruptedException e) {
Log.e("Data Sending Error", e.toString());
e.printStackTrace();
}
}
}
}).start();
return START_STICKY;
}
#Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onDestroy() {
Log.v("SERVICE","Service killed");
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_SHORT).show();
//timer.cancel();
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.setClass(this, com.remote.synchronizer.haris.Login.class);
startActivity(callIntent);
super.onDestroy();
}
}
somewhere i have read that don`t stop the service Android will stop itself. If it is like that then kindly edit my code and tell how can i start a new activity when my work finish. Do i need to stop the timer? Then the onStartCommand will stop and it will call the onDestroy? if yes then how can i stop the timer because i have tried but no success.
if you need a service to stop itself after it completed,you shoud use IntentService
onDestory() is used to release your resource,it will be called when the service is no longer used.
start activity like this:
final Handler mHandler = new Handler() {
public void HandleMessage(Message msg) {
if(msg.what == START_NEW_ACTIVITY) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
callIntent.setClass(this, com.remote.synchronizer.haris.Login.class);
startActivity(callIntent);
}
}
};
public int onStartCommand(Intent intent, int flags, int startId) {
new Thread() {
#Override
public void run() {
// do your job here
mHandler.sendEmptyMessage(START_NEW_ACTIVITY);
}
}.start();
}
To stop the service after your work has been finished simply call stopSelf() or stopSelf(startId).
If you want to start the activity after the service has been finished, Before calling the stopSelf() or stopSelf(startId), you should create the intent of the activity and set the flag mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);.
and start your activity by calling startActivity(intent)
i need to display message to application user when admin pushes message on browser. for that i implemented a timer so that it displays a message to user on application start. timer keeps running to get as message once in 20 minutes if a new message is pushed. my timer is working fine but on button click.
I want my timer to start as soon as activity loads.
Is this proper way to display a message? (it is like banner)
How resource consuming is a timer?
Timer Task
class secondTask extends TimerTask {
#Override
public void run() {
TestBannerActivity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
fl.setVisibility(View.VISIBLE);
long millis = System.currentTimeMillis() - starttime;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
text2.setText(String.format("%d:%02d", minutes,
seconds));
}
});
}
};
button click event
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Button b = (Button) v;
if (b.getText().equals("stop")) {
timer.cancel();
timer.purge();
b.setText("start");
} else {
starttime = System.currentTimeMillis();
timer = new Timer();
timer.schedule(new secondTask(), 8000, 1200000);
b.setText("stop");
}
}
});
you can use this code:
package packagename.timerService;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.app.Service;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.IBinder;
public class TimerService extends Service{
public static final String BROADCAST_TIMER_ACTION = "packagename.timerService.TimerService";
private final Handler handler = new Handler();
private final Handler updateUIHandler = new Handler();
Intent intent;
int time = 0;
private int durationTime = 0;
private int starDate;
private int currentDate;
private Date startTaskDate;
private String taskComment;
#Override
public void onCreate() {
// Called on service created
intent = new Intent(BROADCAST_TIMER_ACTION);
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
try {
handler.removeCallbacks(sendUpdatesToUI);
handler.post(sendUpdatesToUI); //post(sendUpdatesToUI);
starDate = Calendar.getInstance().get(Calendar.DATE);
durationTime = 0;
startTaskDate = new Date();
}
} catch (Exception e) {}
return START_STICKY;
}
private Runnable sendUpdatesToUI = new Runnable() {
public void run() {
try{
displayLoggingInfo();
time ++;
durationTime ++;
handler.postDelayed(this, 60 * 1000); // 1 minute
}catch (Exception e) { }
}
};
private Runnable sendUpdatesToUIOnResume = new Runnable() {
public void run() {
displayLoggingInfoForOnResume();
}
};
private void displayLoggingInfoForOnResume() {
try{
currentDate = Calendar.getInstance().get(Calendar.DATE);
intent.putExtra("changeDate", String.valueOf(false));
intent.putExtra("time", String.valueOf(time == 0 ? time : time - 1 ));
sendBroadcast(intent);
} catch (Exception e) { }
}
private void displayLoggingInfo() {
try{
currentDate = Calendar.getInstance().get(Calendar.DATE);
intent.putExtra("changeDate", String.valueOf(false));
intent.putExtra("durationTime", String.valueOf(durationTime));
intent.putExtra("time", String.valueOf(time));
sendBroadcast(intent);
}catch (Exception e) {
// TODO: handle exception
}
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onDestroy() {
try {
handler.removeCallbacks(sendUpdatesToUI);
updateUIHandler.removeCallbacks(sendUpdatesToUIOnResume);
durationTime = 0;
time = 0;
super.onDestroy();
} catch (Exception e) { }
}
#Override
public boolean stopService(Intent name) {
handler.removeCallbacks(sendUpdatesToUI);
updateUIHandler.removeCallbacks(sendUpdatesToUIOnResume);
durationTime = 0;
time = 0;
return super.stopService(name);
}
}