I\'ve looked around and nothing seems to be working from what I\'ve tried so far...
@Override
protected void onCreate(Bundle savedInstanceState) {
su
You can also use TimerTask
for that.
Here is an method
private void setTimerTask() {
long delay = 3000;
long periodToRepeat = 60 * 1000; /* 1 mint */
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// do your stuff here.
}
});
}
}, 3000, 3000);
}
This Code work for me..
//Get Time and Date
private String getTimeMethod(String formate)
{
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat(formate);
String formattedDate= dateFormat.format(date);
return formattedDate;
}
//this method is used to refresh Time every Second
private void refreshTime() //Call this method to refresh time
{
new Timer().schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
txtV_Time.setText(getTimeMethod("hh:mm:ss a")); //hours,Min and Second with am/pm
txtV_Date.setText(getTimeMethod("dd-MMM-yy")); //You have to pass your DateFormate in getTimeMethod()
};
});
}
}, 0, 1000);//1000 is a Refreshing Time (1second)
}
It would be better if you just used an AsyncTask running using a Timer something like this
Timer LAIATT = new Timer();
TimerTask LAIATTT = new TimerTask()
{
@Override
public void run()
{
LoadAccountInformationAsyncTask LAIAT = new LoadAccountInformationAsyncTask();
LAIAT.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
};
LAIATT.schedule(LAIATTT, 0, 1000);