user935143
user935143

Reputation: 564

make my application start when boot complete on/off

Heloo everyone

im new to android development and im developing an android application for my graduation project my application must start when the device boot up so to that i put these lines in the AndroidManifest file

<!--this to make app run at start up-->
    <receiver android:name="MyIntentReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.HOME" />
        </intent-filter>
    </receiver>

so my program run autmaticlly when boot complete. my question is how to stop this by user?? i want to put a toggle button on/off for this option so the user can chose if he want the app to start automaticlly in background or manually ???

thanks in advance

Upvotes: 0

Views: 503

Answers (2)

PH7
PH7

Reputation: 3916

so my program run automatically when boot complete.

I would say no to that. It is rather you receiver gets notified when boot is completed. From that point on, your program has to decide to fire up your activity/service in onReceive() method of your receiver.

Thus, you will need to save a preference to give option to user. When your receiver gets notified, check the pref setting set by user. For more information about saving preference, you can refer to http://developer.android.com/guide/topics/data/data-storage.html#pref

Upvotes: 1

Camille S&#233;vigny
Camille S&#233;vigny

Reputation: 5143

This sounds pretty straight forward. Basically, when the phone starts, the Receiver class "MyIntentReceiver" will run. Inside this receiver you can put code based on user preferences to either start the application or do nothing. The toggle would be a CheckBoxPreference in the user preferences.

Let me know if you have any questions.

Upvotes: 2

Related Questions