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
am.set(AlarmManager.RTC,  System.currentTimeMillis() + 5000,

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...



Other Threads

1. Mobie Network Receiver

I want to receive notification when Mobile network connection is lost or 
received. Through following code, I can receive notification for Wi-Fi 
(Data) connection but not for Mobile (Voice) connection.

Menifest :

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application android:icon="@drawable/icon" 
        <receiver android:name=".notifier">
                <action android:name="" 

Java :

public class notifier extends BroadcastReceiver {    
    public void onReceive(Context context, Intent intent) {   
        Toast toast = Toast.makeText(context, "Network Changed !!", 

Please tell me, how can I receive notification for Mobile Network (Voice).


2. SurfaceView issue on pause/resume

I am implementing an app that takes images from the camera preview and
displays them on the screen. When the activity is paused and resumed
the surface will no longer display anything that is written to it. The
SurfaceView object appears to be fine but simply won't display.

I have three basic objects:

public class PanoramaCamera extends Activity {} -- the main activity.
public class Preview extends SurfaceView {} -- implements the surface
which gets the camera preview data.
public public class GLLayer extends SurfaceView {} -- implements the
surface which draws the camera images to the screen. This uses OpenGL
to draw the images.

There are multiple Preview objects but only a single GLLayer.

In PanoramaCamera's onPause() method I release the camera for each of
the existing Preview objects, free those objects and even free the
GLLayer object (though I have tried various combinations of the above)
and in onResume() I recreate the objects exactly the same way they
were created on launch. On recreating everything the surface no longer
displays. I can share some code if it helps.

Do I need to do anything special to pause and resume a SurfaceView?



3. Editing XML generated layout in Java.

4. AlertDialog with an mail-to link

5. Broadcast Receiver for Mobile Network

6. Android Library Activity and startActivity

7. Coding style for modal dialog