Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Time refreshing

 
Andi Dan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have the following simple simple sample code:



Every time I run the code, in the emulator and on real device i get the time of the first run. It doesn't update.
In my opinion, every time that I run the code I should get the system time displayed and printed in the Log. This doesn't happen.
I'm new to android ... a help can be useful.
 
Tim Moores
Bartender
Posts: 3135
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing to do with Android, it's basic Java. "c.YEAR" is not an accessor method to retrieve the current year from c, it's a static (i.e., unchanging) number that means something entirely different. What you meant to do is c.get(Calendar.YEAR).
 
Andi Dan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, modified the code using c.get(Calendar.x) according with year etc. and still not working. I'm getting the same time as first run.

I know they are static, the c is formed by using getInstance() instead of new (). Variables should get the values when they're initialized as a first thing.
A new instance of class is created when I start the application with the emulator.
I've changed, i put c.get and still nothing.... same values.

Has anyone have an answer?

 
Andi Dan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:This has nothing to do with Android, it's basic Java. "c.YEAR" is not an accessor method to retrieve the current year from c, it's a static (i.e., unchanging) number that means something entirely different. What you meant to do is c.get(Calendar.YEAR).



no change, replaced with c.get(Calendar.YEAR) and no change, I get the same time value.
 
Tim Moores
Bartender
Posts: 3135
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may sound silly, but are you certain that the app is getting updated on the device or in the emulator? What is the code you're now using?
 
Przemek Boryka
Ranch Hand
Posts: 51
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Take look at this:



Maybe it will help you, solve your problem ;)
 
Andi Dan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you tks, problem solved with Date date=new Date();, but not with Calendar.

Does anyone know why is not working with Calendar?
 
Przemek Boryka
Ranch Hand
Posts: 51
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Date and Calendar are different class that provide different methods in each other. Better to you, will be using GregorianCalendar class, the class is not abstract like Calendar class, but is a subclass of Calendar.



GregorianCalendar object has many different methods to manipulate the date, time. You can format the myCalendar object in the same style as Date object, by SimpleDateFormat object.

Try to make in pure Java, a few examples, using GregorianCalendar class.

Bye. Sorry for my english, I'm still learning.
 
Andi Dan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've stopped using Calendar and use only Date date_current = new Date(); and then date_current.getTime(); getHour(); etc.

Yes it's better to use Gregorian.

Tks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic