Running Background Process

Put your problem here if it does not fit any of the other categories.

Running Background Process

Postby jjalan » Sun Jul 13, 2008 3:49 pm


I have written an intentreceiver which gets launched when the boot has completed. In this, I run a thread in the background process which do certain task periodically. Here is my piece of code:

public class AddressLogService extends IntentReceiver{
/* the intent source*/
static final String ACTION = "android.intent.action.BOOT_COMPLETED";
public void onReceiveIntent(Context context, Intent intent) {
if (intent.getAction().equals(ACTION))
NewRunnable AddressLog = new NewRunnable(context);
Thread tr = new Thread(null,AddressLog,"Address Logger");

private class NewRunnable implements Runnable {
private Context context;
// Initializing the Runnable Class
public NewRunnable(Context c){
context = c;
public void run(){
isServerUp = true;
if(isServerUp ){
// Do some processing
Thread.sleep(15 * 1000);
}catch(Exception e){}

I have included the required receiver details and permission in AndroidManifest.xml
The problem is when I launch my emulator, this thread sometimes run and sometime it does not run. I have to try launching the emulator certain times before I get this thread running. I check this by checking the server log. I am not sure why this is happening. Can any point me out why this is happening? Or is anyone can suggest there is any other better way to approach this task.

Posts: 6
Joined: Mon Jun 16, 2008 1:05 pm


Return to Other Coding-Problems

Who is online

Users browsing this forum: Google Feedfetcher and 12 guests