Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run my application in background when i start device power on in android [duplicate]

Tags:

android

Possible Duplicates:
how to create startup application in android?
How to Autostart an Android Application?

Hi,

I am trying in one of my application when i am going to start i mean power on my google android g1 my application automatically will start but i am unable to understand how can i do that please help......

like image 491
Pankaj D. Gaurshettiwar Avatar asked Jun 04 '10 12:06

Pankaj D. Gaurshettiwar


1 Answers

Here's a basic example of what I think you're trying to do. You'll need to do a few things. First, grant your application permission to listen for a "Boot completed" signal. In your AndroidManifest.xml, add this line in the manifest section:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Under your application section, add and specify a broadcast receiver for this intent:

<receiver android:name=".MyBroadcastReceiver">
    <intent-filter>
         <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

You also need a broadcast receiver which will respond to this intent and start your service at boot. Create MyBroadcastReceiver.java in your project:

package com.mypackage.myapp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context aContext, Intent aIntent) {

        // This is where you start your service
        aContext.startService(new Intent(aContext, MyService.class));
    }
}
like image 158
Scott Ferguson Avatar answered Oct 16 '22 04:10

Scott Ferguson