Page 82

Android Programming Cookbook

74 / 143

android:theme="@style/AppTheme"> <activity android:name="com.javacodegeeks.androidserviceonbootexample.MainActivity" 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 >

In this AndroidManifest.xml we register the application to listen to android.intent.action.BOOT_COMPLETED. Additionally, we register the android.intent.action.PACKAGE_REPLACED and the android.intent.action. PACKAGE_ADDED events. These events can catch the installation and update of our application, so that our service will start not only on device boot, but on application update. We also have to register our service in the AndroidManifest.xml. This happens at line 24.


Build, compile and run

When we build, compile and run our project, the main Android ServiceStart OnBoot application should look like this:


This is Yahya Christian School Magazine

Read more
Read more
Similar to
Popular now
Just for you