1

Hi am trying to start the application on boot. App starts whenever boot completed but application launched and activity screen came to front. I want to start the app on boot but wont get launched. i included the manifest and BootUpReceiver.java .. Thanks.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.startapp"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />


    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <receiver android:enabled="true" android:name=".BootUpReceiver"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
        <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />

        </intent-filter>
    </receiver>
        <activity android:name=".StartApp"
                  android:label="@string/app_name">  
        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>         
        </activity>

    </application>
<manifest>

BootUpReceiver.Java

public class BootUpReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent arg1) {
     Intent i = new Intent(context, StartApp.class);  
     i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     context.startActivity(i);
   }
}
Siva
  • 71
  • 5

2 Answers2

0

I think you would like to start a Service which runs in the background instead of an Activity. There is a question regarding that issue here.

Community
  • 1
  • 1
dmaxi
  • 3,267
  • 1
  • 18
  • 15
  • @maxi No i don't want to start service. am trying to start app in background without launching after boot. – Siva Jan 03 '12 at 12:34
  • You can't start Activity in the background, you can run only Service in the background and that can start an Activity for you if you need it. – dmaxi Jan 03 '12 at 13:37
0

Could it be that you are testing this on a HTC and have "Fast boot" enabled (Settings -> Power -> Fast boot). In that case no BOOT_COMPLETED will be sent.

Some more information in my question Detect if HTC “Fast boot” is enabled

Community
  • 1
  • 1
tidbeck
  • 2,363
  • 24
  • 35