HTC Incredible suffering a reset while service running.

by Nathan » Wed, 19 May 2010 06:16:43 GMT


Sponsored Links
 Based on scanty evidence, I am leaning toward this being an event loop
clogging.

My experiment on a G1 ran for two hours and did not crash. But the UI
on the device was unresponsive to where clicks could take. The HTC
Incredible could be shutting down as a defense mechanism.

I am already trying *not* to call AsyncTask.publishProgress too
often.

Here I am checking to see that the last time was at least 10 seconds
ago.

        n.setToNow();
        // only update every four seconds or so.
        if (n.toMillis(false) - lastupdate.toMillis(false) > 6000) {
                this.publishProgress(new DownloadProgress(progress));
                lastupdate.setToNow();
        }

Context.getString(int resId, Object... formatArgs)

What happens in onProgressUpdate is not very complex, but it does
update a notification with a status bar. in the process, it calls
Context.getString(int resId, Object... formatArgs)which I believe.

I know String.format to be extremely slow in Android and even slower
in debug mode. It's bitten me before. I don't think it would take 6
second, but who knows.

Any insights are still welcome.

I'd like to find the right balance of how often to call
publishProgress(). Too often and it could freeze (or even reset). Too
seldom and the user will think it is frozen because they don't see any
progress.

Nathan

--



HTC Incredible suffering a reset while service running.

by Nathan » Fri, 04 Jun 2010 01:43:15 GMT


 After a few weeks, I've narrowed this down somewhat. But what to do,
I'm not sure.

I suspected that frequent notification updates were clogging up the
phone. As another developer pointed out, the Incredible won't give
foreground priority to services that follow that procedure - this
could be related.

Since my application doesn't reboot the phone, I suspect that

I've tried all kinds of things to reduce the notifications:
1. Not calling AsyncTask.publishProgress more than every six seconds -
logical to do.
2. Rejecting an event in if it is more than six seconds old.
3. Not updating the notification if it has been updated within the
last few seconds.
Finally,
4. Use an atomic boolean as a semaphore to not call publishProgress if
a previous onProgressUpdate has not completed.

The only thing that has worked was when I had a bug that caused the
updates not to be sent at all. In that case, a beta tester managed to
run the service for 24 hours and download 2 gigs in small pieces.
There was absolutely no indication of status - it said 1/215000 the
whole time, but it stayed alive. Put the update back in, and it can't
run for very long.

There is some bug on the Incredible related to notifications from
services. I don't know how to avoid hitting it yet.

Does anyone have any insights?

One of my beta testers might be within travel range to hook up a
debugger, but I'm not sure even that will help.

For reference, this is what I do for updating the notification:

                        // update the text on the ongoing notification
                        message = mDownloadExplanation +  label + " " + num + " 
/ " +
total;

                        RemoteViews contentView = mNotification.contentView;
                        
contentView.setProgressBar(R.id.download_progress_horizontal,
total,
                                        num, false);
                        
contentView.setTextViewText(R.id.download_progress_explanation,
message);

                        long now = System.currentTimeMillis();
                        if(now-mNotification.when>MINTIMEBETWEENUPDATES)
                        {
                                mNotification.when = System.currentTimeMillis();

                                
mNotificationManager.notify(DOWNLOAD_PROGRESS_ID, mNotification);
                        }
                        mUpdateInProgress.set(false);

I've been disappointed enough to consider not using a Service for this
at all, but it still seems like a good fit - for everything but the
incredible.

Nathan

--


Sponsored Links


HTC Incredible suffering a reset while service running.

by nikhil » Fri, 04 Jun 2010 03:47:31 GMT


 Nathan,

I had similar issue long time back when I had implemented the service
architecture. I had observed few things:

1. My phone (Nexus One) used to restart (with my service running in
background) when I tried to change the call forward setting or I tried
to use the google car navigator app.
2. The phone did not restart if it was plugged into a computer. (May
be related to network connectivity.)

I tried all kind of stuff the only way I was able to get my app
working was by referring to Mark Murphy's wakefulintentservice
structure which uses the alarm manager.




--



HTC Incredible suffering a reset while service running.

by Nathan » Fri, 04 Jun 2010 04:29:02 GMT


 


Thanks.

Did you find out why the restart was triggered? Or did you simply
managed to avoid it? Was it because of many notifications, or just the
fact that it was running for long time, or that Android tried to kill
it?

The alarm manager isn't appropriate for this task, at least I don't
think so, because it is not a service that wakes up periodically and
does some work.

It has a defined list of files to download and then finishes, but it
is actively working all that time.

Nathan

--



HTC Incredible suffering a reset while service running.

by nikhil » Fri, 04 Jun 2010 12:15:28 GMT


 I am not sure about the exact reason but I feel it was because of
mishandling of partial wakelock. Like your app, I had a service which
remained active all time and for that I had to hold on to the
wakelock. The phone did not restart if I commented out my wakelock
code. Interesting thing is it never restarted untill I tried to change
call forward setting or use car navigator app (thankfully, this was
observed when we tested the app for any kind of conflicts) .Then I
realised that I should not hold on to the wakelock for long,  to avoid
conflicts. When I went the AlarmManager way all conflicts vanished.
Are you holding on to wakelock? If you are, you may try commenting out
that part and keep your app active until download is complete so that
you don't loose network connection. Just perform few tests with the
wakelock thing hopefully you should get the answer. You may have to
split your file download into batches so that you can release the
wakelock.








--



HTC Incredible suffering a reset while service running.

by Nathan » Fri, 04 Jun 2010 23:02:25 GMT


 I haven't even used a wakelock yet, so I don't think a wakelock is the
problem.

I've thought of using a brief wakelock around a single file download.
But I also think that users can leave the phone plugged in if they
want the download to complete soon.

Nathan






--



HTC Incredible suffering a reset while service running.

by nikhil » Sat, 05 Jun 2010 05:02:45 GMT


 How do you not loose network connectivity without holding on to
wakelock?

Any secrets :P

Or does the user keep the app active untill the download ends.








--



HTC Incredible suffering a reset while service running.

by Nathan » Sat, 05 Jun 2010 06:01:40 GMT


 



I don't know actually. Maybe the notification activity is actually
keeping it active. But it is more likely that the users are plugged
into power. Downloads also have a timeout and up to three retries.

Are you saying that the device will turn off wifi/network before it
goes into power save and shuts down the whole thing?

Maybe I need the wakelock, but now you have me worried about trying
it, if it will cause other problems.

Right now, I believe I will shut down on battery power and then
continue when restarted.

If I acquire a wakelock, then I will probably run the battery down for
sure if the download takes hours.

Nathan

--



HTC Incredible suffering a reset while service running.

by Kostya Vasilyev » Sat, 05 Jun 2010 06:07:06 GMT


 It's the other way around with WiFi and the screen - first, the screen
switches off, then WiFi (after a delay).

05.06.2010 2:02  "Nathan" <critter...@crittermap.com> :



I don't know actually. Maybe the notification activity is actually
keeping it active. But it is more likely that the users are plugged
into power. Downloads also have a timeout and up to three retries.

Are you saying that the device will turn off wifi/network before it
goes into power save and shuts down the whole thing?

Maybe I need the wakelock, but now you have me worried about trying
it, if it will cause other problems.

Right now, I believe I will shut down on battery power and then
continue when restarted.

If I acquire a wakelock, then I will probably run the battery down for
sure if the download takes hours.


Nathan

--



HTC Incredible suffering a reset while service running.

by Nathan » Sat, 05 Jun 2010 06:24:15 GMT


 


So when does the CPU turn off? After wifi?

Nathan

--



HTC Incredible suffering a reset while service running.

by Kostya Vasilyev » Sat, 05 Jun 2010 07:11:44 GMT


 I was talking about WiFi vs. the screen - not the CPU state. That, I don't
know.

05.06.2010 2:24  "Nathan" <critter...@crittermap.com> :





So when does the CPU turn off? After wifi?


Nathan

--



HTC Incredible suffering a reset while service running.

by nikhil » Sat, 05 Jun 2010 23:39:35 GMT


 CPU takes down wifi..In other words, because CPU turns off it takes
wifi with it.. Thats why we require wakelock to keep it alive.
Anyways, if you are not using wakelock and if your app is making the
phone reboot on its own, then may be you will have to check for memory
leakage or something like that...




>



Other Threads

1. Content provider example besides Contacts.

Hi there. I'm trying to develop a simple APN changer. I checked the
tutorials and the CP are basicaly some sql databases accesed with a
pointer. The thing is, for example, that the APN value seems to be in
the settings DB? I dont find a clear reference to that in the API nor
i can access it using the technique shown in the Contacts tutorial.

Some lines of code to illustrate how to access the APN info me would
be really apreciated! Sorry if this is terrible newbish, but cant find
a simple non contact based tutorial regarding CPs.

-- 

2. Fabook! App Facebook chat

Real android Facebook chat application!...kekekekekekeke...

Paid app...u know jalan ke pasar malam?

Hajaaaaaaar...

-- 
"Indonesian Android Community [id-android]" 

3. Produk baru motorola with big vibrate menu

4. How can I remove an item from ExpandableListView or how can I reload an single group from ExpandableListView?

5. Bluetooth RFCOMM connection dying immediately after .connect()

6. Perbedaan Android dan iPhone

7. Reading "Name (phonetic)" field on Eclair