Service restarting for no reason?

by DCheeseman » Thu, 11 Mar 2010 22:56:47 GMT


Sponsored Links
 hile debugging one of my apps (one that sits in the background and
logs accelerometer data), I noticed that it would randomly and without
any prompt reset itself. It would be running it's normal timer task
and suddenly it would stop, the create function would be called and
any running task would halt. Here's the trace:

03-11 07:50:34.574: VERBOSE/AccelerLogService(29277):
0.088633,1.253072,1.103248,9.629586
03-11 07:50:34.584: VERBOSE/AccelerLogService(29277): History Size:
0.083333336
03-11 07:50:35.064: VERBOSE/AccelerLogService(29277):
0.096283,1.253072,1.035146,9.629586
03-11 07:50:35.084: VERBOSE/AccelerLogService(29277): History Size:
0.1
03-11 07:50:35.544: VERBOSE/AccelerLogService(29277):
0.104550,1.253072,1.007906,9.575105
03-11 07:50:36.044: VERBOSE/AccelerLogService(29277): History Size:
0.11666667
03-11 07:50:36.484: VERBOSE/AccelerLogService(29277):
0.120600,1.239452,1.035146,9.615966
03-11 07:50:37.024: VERBOSE/AccelerLogService(29277): History Size:
0.13333334
03-11 07:50:38.994: VERBOSE/AccelerLogService(29277):
0.136867,1.293933,1.035146,9.615966
03-11 07:50:39.014: VERBOSE/AccelerLogService(29277): History Size:
0.15
03-11 07:51:03.984: VERBOSE/AccelerLogService(29395): CREATED
03-11 07:52:41.624: VERBOSE/AccelerLogService(29502): CREATED

And here's the service code:

public class AccelerLogService extends Service implements
SensorEventListener {
private static final String LOG_TAG = AccelerLogService.class
.getSimpleName();
private static final String base_dir = "/sdcard/";
private static WakeLock wl;

private long startTime;
private volatile float[] lastData;
private static Queue<float[]> lastFiveMinutes;

private static BufferedWriter br;
private static Timer timer;
private static TimerTask tt;
float threshold = 0.0f;
int interval;

private boolean getAccelerometer() {
SensorManager sensorMgr = (SensorManager)
getSystemService(SENSOR_SERVICE);
List<Sensor> sensorList = sensorMgr
.getSensorList(Sensor.TYPE_ACCELEROMETER);
boolean addedListener = sensorMgr.registerListener(
(SensorEventListener) this, sensorList.get(0),
SensorManager.SENSOR_DELAY_UI);
if (addedListener)
Log.v(LOG_TAG, "Listener Added");
else
Log.v(LOG_TAG, "Listener Not Added");
return addedListener;
}

@Override
public void onCreate() {
super.onCreate();
if (timer == null)
timer = new Timer();
if (lastFiveMinutes == null)
lastFiveMinutes = new LinkedList<float[]>();
Log.v(LOG_TAG, "CREATED");
}

@Override
public void onStart(Intent intent, int startid) {
super.onStart(intent, startid);
Log.v(LOG_TAG, "STARTED");
if (intent.getExtras().containsKey("ms")) {
interval = intent.getExtras().getInt("ms");
} else {
interval = 5000;
}
s



Service restarting for no reason?

by Mark Murphy » Thu, 11 Mar 2010 23:53:34 GMT


 


Do not use TimerTask with an unbound Service. Use AlarmManager, so the
Service does not have to remain in memory all the time.

 http://github.com/commonsguy/cw-advandroid/tree/master/SystemServices/Alarm/ 


WakeLocks have nothing to do with keeping services in memory. In
general, you don't *want* to keep services in memory any more than is
necessary.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_Android Programming Tutorials_ Version 2.0 Available!

--


Sponsored Links


Other Threads

1. request: program email compose richtext untuk gmail bawaan

Sesuai judul, gue pengen request program plugins untuk composing email di
gmail yang bisa plaintext, bold, italic, underline dll

*Jadi prinsipnya seperti kaya gue ketik email ini langsung di android dengan
gmail, tapi ini bisa karena gue akal2an dengan program Pulse > share
article, lalu isi emailnya gue edit hehehe...*

Ketikkan diatas bisa jadi bold kan, sedangkan yang ini plain biasa..

Nah programnya mungkin bisa kerja seperti kaya Pulse/FeedR pas "share
article" tapi sebelumnya kita yang editing text nya sehingga bisa richformat
lalu begitu export bisa ke gmail...

Bisa kan idea seperti itu? Yahoo mail aja bisa compose HTML, masa gmail gak
bisa... yah gue request programnya hehe

Paging android developers \(`_)bd(_)/

Thank you - don't hate Monday...

Dibawah sisa article yang gue edit....

MASHABLE!

http://feeds.mashable.com/~r/Mashable/~3/ouyiv6N6P3g/<http://pulsene.ws/lT6T>

--rc
HTC HD2 JDMS v1.5 PPP hastarin 8.4_eb

-- 
===============
"

2. cache detik

suhu mau tanya nih tentang aplikasi detik.com

kayanya tiap buka aplikasi detik gambar2nya kesimpen yak?  jadinya di
gallery banyak bener ini gambar2 dari detik.  gimana ini biar ga otomatis
kesimpen?

matur suwun

-- 
Solidaritas Serumpun Indonesia (Serunai)
Bank Mandiri KCU Imam Bonjol Jakarta
122-00-0565711-2
a/n Mariski SE/Terra Nova Melati
http://serunaiku.blogspot.com/

-- 
===============
"

3. Detecting Task Resume

4. Intent loading issue in MenuItem

5. List child item focus change

6. Query on Customs Map application

7. Handling Android device without Menu button