0

Currently i am listening for android.intent.action.TIME_TICK to show the current system time in a TextView, thats working perfectly. Now i need to do something different.

Once when my app is starting it gets a string with a time in it (for example: "15:30". I need to display this time in a TextView also and it must update itself like it is the real local time.

To make it more clear, it's like you manually set androids system time to something you specify, like your own timezone.

I don't know how to achieve this with the Date/Time object and how to increase it every 1 minute.

Anybody has some tips on how to achieve this? Maybe i miss something really easy to create my own custom clock

Digit
  • 3
  • 4
  • create a `receiver` which continuously fetch the system time and update your time in `TextView` – Ved Jul 26 '14 at 10:01
  • I mentioned that i already have a receiver and thats not the problem. How to add 1 minute each time to the text "15:30" for example? The system time i dont need here. – Digit Jul 26 '14 at 11:53
  • You also use `TimerTask` to update your time in every 1 min or any fix time intervals. – Ved Jul 26 '14 at 12:18
  • As i said before its not about how to trigger some code every 1 minute. I already solved it and will post the code in a 2 hours when the system allows me to do it. – Digit Jul 26 '14 at 16:13

1 Answers1

0

Luckily i found a solution by myself and wanted to share it.

Every minute my broadcast receiver updates the initially received time string in mCustomClock. This is the code in my broadcast receiver, didnt know its so easy

        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        Calendar c = Calendar.getInstance();
        try {
            c.setTime(sdf.parse(mCustomClock));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        c.add(Calendar.MINUTE, 1);

        mCustomClock = Integer.toString(c.get(Calendar.HOUR_OF_DAY)) + ":" +
                String.format("%02d", c.get(Calendar.MINUTE));
Digit
  • 3
  • 4