Running code on phone boot
Some applications, for example a mail client, needs to run in the background all the time. You may want to run code right after the device booted.

The device is booting
In the Android system BroadcastReaceivers are just for such mechanism, they can listen for defined intents with given parameters, and run code when they receive one, even when your application is not running at the moment. You can define own actions and fire the manually to control your receivers, but there are a lot of predefined broadcast in the system that are fired automatically on certain events.
One of the is the BOOT_COMPLETED action. The complete list is available here.
All you need to do is a class that extends Broadcastreceiver:
- public class HelloReceiver extends BroadcastReceiver {
- @Override
- //code inserted here will run at phone boot
- //you may start a Service
- //or an AlarmManager to run code later too
- }
- }
Then register it in the AndroidManifest.xml:
- <receiver android:name="HelloReceiver">
- <intent-filter>
- <action android:name="android.intent.action.BO
OT_COMPLETED" /> - <category android:name="android.intent.category.
HOME" /> - </intent-filter>
- </receiver>
The BOOT_COMPLETED broadcast needs a permission to use, so don't forget to add this too:
- <uses-permission android:name="android.permission.RECEI
VE_BOOT_COMPLETED"></uses-permission>
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@Idevicegazette (iDevice Gazette)
GSM-to-Skype bridge lets you lose those roaming fees http://bit.ly/lbRJeh #android
11 years 37 weeks ago -
@tommy_banane (tom b.)
RT @AndroidFavorite: #Android New Desktop Android Market Is Live, Adds Several New Features http://zorr0.nl/lFwXNz
11 years 37 weeks ago -
@dwilliams5 (Dennis Williams)
just completed a runtastic run of 3.02 km in 40 min 11 s with #runtastic #Android App: http://tinyurl.com/5tvrpe3
11 years 37 weeks ago -
@S_Pinz (Spinz!)
RT @Androidheadline: Out of box #LG Optimus 3D got Quadrant 2420 score. Thanks @blink_c #io2011 #android http://twitpic.com/4whkdz
11 years 37 weeks ago -
@tayaitapps (Taya IT)
Next Google TV Looks A Lot Like Android http://t.co/dvlTim3 via @alleyinsider #google #apple #android #tv #honeycomb
11 years 37 weeks ago
Poll
Useful resources
Android Development Projects
- iOS/Android Developer to take older Games and bring them Current
- Android apps developer - need to finish urgent.
- Buliding MobileApp For onlie order
- looking for android APP developers
- Create an ecommerce app
- text-to voice for smartphones IOS - GOOGLE - HARMONY - AND ALEXA
- Optimize Images on App
- Create small feature with drag-drop text for Android
- Scouting for advanced website and Mobile apps developers. Potential Long-term contract.
- BLACK SCREEN