hi, bellow just a test sample source for a background thread. i would like that when my app is closed it still run in the background (like at my tracks) to collect data even when it is closed.
but it always dies after a while by itself, why? thanks chris package com.chris.alarmer; import android.app.Activity; import android.os.Bundle; import android.util.Log; public class alarmer extends Activity { /** Called when the activity is first created. */ @Override public void onDestroy() { super.onDestroy(); Thread thr = new Thread(null, mTask, "alarmer"); thr.start(); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Thread thr = new Thread(null, mTask, "alarmer"); thr.start(); } Runnable mTask = new Runnable() { public void run() { // Normally we would do some work here... for our sample, we will // just sleep for 30 seconds. Log.i("DATABASE-TEST","-----------: START THREAD"); long endTime = System.currentTimeMillis() + 99999*1000; long endTime2 = System.currentTimeMillis() + 10*1000; while (System.currentTimeMillis() < endTime) { //get data after 10 seconds if (System.currentTimeMillis() > endTime2) { endTime2 = System.currentTimeMillis() +10*1000; Log.i("DATABASE-TEST","-----------: GET DATA"); } } Log.i("DATABASE-TEST","-----------: END THREAD"); // Done with our work... stop the service! // alarmer.this.stopSelf(); } }; } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---