How to make a widget that doesn't drain the battery and updates often

by Chister Nordvik » Sun, 06 Jun 2010 02:38:47 GMT


Sponsored Links
 > Frankly, I don't know why the Genie... service sticks around for the

Neither do I, but it seems "everyone" is taking this approach. I
really really miss guidelines on Android development. Both GUI design
guidelines (toolbars at the bottom anyone?) and design guidelines for
widgets doing more advanced things than updating a clock. It must be
100 different toolbars out there at the moment in various sizes. Why
can't we have a proper toolbar in Android? Sorry, off-topic :-)


I would love to see some better suggestions :-)

No wake-locks. Only using the following code to make the widget change
headline:
...
am.set(AlarmManager.RTC,  System.currentTimeMillis() + 5000,
pendingIntent);
...

According to the documentation this should work just brilliant. But my
phone is dead every morning with my widget running. Uninstalled!


Well, people will blame my widget even if I try to tell them that they
have another application that has wake_locks so I must make my widget
behave nicely with the rest of the apps out there.

Well I have made a new service that runs all the time and receives
broadcast events for screen off and on and that works great, so maybe
I'll stick with this. When I have started 10 of my favourite apps I
have a lot of services running so I guess people are used to this.
Seems like services is a bit overused these days so no wonder everyone
complains about battery life with Android...

-Christer


--



Other Threads

1. How to get current pure UTC time?

I need to get pure UTC time in application level.
It should not be changed by user or location or anything else.
When I try with System.currentTimeMillis() or getTime() of Date class,
they always return value of local time. If user change date or time,
the return value is also changed.
I found handleEndOfInit method in android_modem.c (external\qemu
\telephony)
and the method is like below.
Probably, the variable "utc" is what I want.

1. Is the android_modem.c for emulator??
2. If it is, I think there must be similar file for target. Where is
it?
3. How can I get the "utc" value in my application?


static const char*
handleEndOfInit( const char*  cmd, AModem  modem )
{
    time_t       now = time(NULL);
    struct tm    utc, local;
    long         e_local, e_utc;
    long         tzdiff;
    char         tzname[64];

    tzset();

    utc   = *gmtime( &now );
    local = *localtime( &now );

    e_local = local.tm_min + 60*(local.tm_hour + 24*local.tm_yday);
    e_utc   = utc.tm_min   + 60*(utc.tm_hour   + 24*utc.tm_yday);

    if ( utc.tm_year < local.tm_year )
        e_local += 24*60;
    else if ( utc.tm_year > local.tm_year )
        e_utc += 24*60;

    tzdiff = e_local - e_utc;  /* timezone offset in minutes */

   /* retrieve a zoneinfo-compatible name for the host timezone
    */
    {
        char*  end = tzname + sizeof(tzname);
        char*  p = bufprint_zoneinfo_timezone( tzname, end );
        if (p >= end)
            strcpy(tzname, "Unknown/Unknown");

        /* now replace every / in the timezone name by a "!"
         * that's because the code that reads the CTZV line is
         * dumb and treats a / as a field separator...
         */
        p = tzname;
        while (1) {
            p = strchr(p, '/');
            if (p == NULL)
                break;
            *p = '!';
            p += 1;
        }
    }

   /* as a special extension, we append the name of the host's time
zone to the
    * string returned with %CTZ. the system should contain special
code to detect
    * and deal with this case (since it normally relied on the
operator's country code
    * which is hard to simulate on a general-purpose computer
    */
    return amodem_printf( modem, "%%CTZV: %02d/%02d/%02d:%02d:%02d:%02d
%c%d:%d:%s",
             (utc.tm_year + 1900) % 100, utc.tm_mon + 1, utc.tm_mday,
utc.tm_hour, utc.tm_min, utc.tm_sec,
             (tzdiff >= 0) ? '+' : '-', (tzdiff >= 0 ? tzdiff : -
tzdiff) / 15,
             (local.tm_isdst > 0),
             tzname );
}

-- 

2. Which Eclipse?

This page
http://developer.android.com/sdk/installing.html#Preparing
says
"f you need to install Eclipse, you can download it from this
location:

http://www.eclipse.org/downloads/"

But that location has many different versions - which one is the right
one?

-- 

3. Ensure GPS has fix before proceeding..

4. airplane mode on

5. Some confusion on resource IDs

6. Problem Installing app

7. two programming questions about 'twitter for android' app