Skip to content Skip to sidebar Skip to footer

Auto Start Application After Boot Completed In Android

I want to make an application which has auto start option in its settings. I have made Settings activity in my application which is derived from PreferenceActivity and give CheckBo

Solution 1:

You can use the shared preference to store a Boolean value for isAutoStartEnabled, and check this value in the BroadcastReciver, fire an intent only if it's true.

In your case, the problem is not whether you receive the broadcast but who receives the broadcast. Best of luck..

I hope it helps..

Solution 2:

I think from Android 3.1 onwards your BroadcastReceiver which receives BOOT_COMPLETED intent its not going to work. User have to in-wake the application by interacted with it.

So, After booting the device all third party application are lying as a stop.

And for currently your application you can use SharedPreferences for Auto-Start your application..

UPDATE: (Only for Android version below 3.1 for higher version it works but you have to user interaction with your application after boot completed on device)

You need to use a BroadcastReceiver with android.intent.action.BOOT_COMPLETED intent.

Add following to your manifest file:

<receiverandroid:name="App_Receiver"><intent-filter><actionandroid:name="android.intent.action.BOOT_COMPLETED" /><categoryandroid:name="android.intent.category.DEFAULT" /></intent-filter></receiver>

App_Receiver class implementing BoradcastReciever. Implement the onReceive() method and start your favorite activity from your app.

publicvoidonReceive(Context context, Intent intent) {
    // make sure you receive "BOOT_COMPLETED"// Here isAutoStartEnabled check sharedPreferences for Auto Start flagif ( isAutoStartEnabled ) {

    if ((intent.getAction() != null) && (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")))
    {
        // Start the service or activity 
    }
}

Solution 3:

You have to add the uses-permission android.permission.RECEIVE_BOOT_COMPLETED in your Manifest.

Solution 4:

finalSharedPreferencessharedPreferences= getSharedPreferences("Application", MODE_PRIVATE);
        booleanisAutoStartEnabled= sharedPreferences.getBoolean("isAutoStartEnabled", false);

        if ( isAutoStartEnabled ) {
            startActivity(newIntent());
        } 

I hope this helps you

Solution 5:

The following code works for me:

publicclassBootCompleteReceiverextendsBroadcastReceiver {
    publicstaticfinalStringPREFS_NAME="MyPrefsFile";  

    @OverridepublicvoidonReceive(Context context, Intent intent) {
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
            Log.d("boot completed", "boot completed caught");
            BooleanautoRestart=false;
            SharedPreferencessp= context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
            autoRestart = sp.getBoolean("autoRestart", false);

            if (autoRestart){

                Log.d("boot completed", "auto restart true");

                Intenti=newIntent(context, WelcomeScreen.class);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);

            }
        }
    }

}

Post a Comment for "Auto Start Application After Boot Completed In Android"