Leaking Service ... vs. stopped service. middle ground??

by Hunter Peress » Fri, 12 Mar 2010 01:34:29 GMT

Sponsored Links
 If I don't unbind a service of mine in onPause,then a back button
press will cause a leaking service. if i do unbind the service in
onPause, then the service doesnt leak but it stops. So how can I
unbind (to prevent leaking onBackButtonPress) yet still allow the
service to run  (my service is startForegrounded...so I suspect a 2nd
service is being created)


Other Threads

1. ListView not receiving trackball focus if setContentView called asynchronously

I have an Activity which has a ListView as its content View. I need to
call Activity.setContentView after a short asynchronous delay from
when Activity.onCreate is called (because there is a delay loading a
network resource needed to fully construct the ListView's
ArrayAdapter). In this case, it seems that the ListView won't enter
trackball mode or receive focus, unless I first touch the screen.

I have tried to distill this to a minimal example pasted below. There
is a comment at the top of the class explaining how the two variables
control the examples behavior.

Any ideas on how I can re-enable trackball mode, without requiring the
user to first touch the screen?

package foobar.androidtest;

import android.app.*;
import android.os.*;
import android.widget.*;

// With the settings SYNCHRONOUS=false and SLEEP=3000, then
// when the ListView is displayed, the first item won't be
// highlighted, and the trackball doesn't work.
// However, if you either change SYNCHRONOUS=true or SLEEP=0
// then when the ListView is displayed, the first item is
// highlighted, and the trackball works just fine.
public class AndroidTest extends Activity {
    private static final boolean SYNCHRONOUS = false;
    private static final int SLEEP = 3000;

    public void onCreate(Bundle bundle) {
        if(SYNCHRONOUS) {
        else {
            final Handler mainThreadHandler = new Handler();
            Runnable backgroundThreadRunnable = new Runnable() {
                public void run() {
                    Runnable mainThreadRunnable = new Runnable() {
                        public void run() {
            Thread backgroundThread = new Thread

    private void doSetContentView() {
        String[] strings = new String[] {
            "SLEEP: " + SLEEP,
            "third item",
            "fourth item",
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
            this, android.R.layout.simple_list_item_1, strings);
        ListView listView = new ListView(this);

    private void optionalSleep() {
        if(SLEEP > 0) {
            try {
            catch(InterruptedException interruptedException) {
                throw new RuntimeException(interruptedException);


2. GPS reading jumps a thousand miles or more

my android app that is a location listener gets fairly good data but
once in a while the location jumps by a thousand miles or more and
stays there for numerous updates with no corresponding major increase
in the (in)accuracy reading.

for example you can see that at 3:07 and 3:09  and 3:10 i was in
portland oregon with less than 1024 meters of accuracy. at 3:48 i get
consistent readings in the pacific ocean, with a supposed accuracy of
less than 1024 meters in the first two readings.

donpG1  2008-12-17 03:57:59 UTC         53.5545998811722        
donpG1  2008-12-17 03:55:58 UTC         53.5575771331787        
donpG1  2008-12-17 03:53:58 UTC         53.5582852363586        -135.15274643898
donpG1  2008-12-17 03:51:59 UTC         53.5593849420547        -135.15048801899
donpG1  2008-12-17 03:49:58 UTC         53.5648941993713        
donpG1  2008-12-17 03:48:49 UTC         53.5753923654556        
donpG1  2008-12-17 03:10:36 UTC         45.5137449502945        
donpG1  2008-12-17 03:09:02 UTC         45.5137234926224        
donpG1  2008-12-17 03:07:01 UTC         45.5135464668274        

whats odd is that the location is not a random reading but consistent
readings in the same wildly inaccurate place. its almost like the G1
starts playing a debugging kml file buried deep in the the GPS code.


3. Porting to DaVinci EVM

4. Installation on HTC Wizard

5. need clarification on resolving intents.

6. Starting new group for Android OpenMax

7. Job Openings in Northern Virginia for Android Developers