Search code examples
androidstartupboothomescreendedicated

What is the best approach for autostarting an Android app on a dedicated device?


I am new to Android programming, and am working on an app that will provide an interface to an appliance. The Android device the app will run on will be attached to the appliance and used only for controlling the appliance. The app I am working on will be the only app ever run on the dedicated Android device.

One of the requested features is to have the app start automatically when the Android device starts up. I have implemented this feature by detecting the ACTION_BOOT_COMPLETED intent, as described in this thread. I have, however, seen an alternative approach recommended of making the app the home screen, as described in this thread.

I realize that implementing the autostart feature by detecting ACTION_BOOT_COMPLETED, as I have done, may well not be the best approach to take for Android apps in general. But, as mentioned, in my case the app I am developing will be the only app ever used on the device. Given that, is the approach I am taking reasonable? Or is there a better way to implement the autostart feature?

Note that one consideration is ease of configuring the Android device. For the approach I am taking, there will be one manual step required, of launching the app the first time. But it looks like there would also be a manual step required if I took the alternative approach of making the app the home screen, so in that regard there would be no advantage to taking that approach.

Thank you for your help!

EDIT: I have tried setting the app as the home screen by modifying AndroidManifest.xml as Holmes suggested below. Here is what I've found so far in my comparison of the two approaches: (1) The code is much simpler using the home screen approach, requiring only a minor tweak to AndroidManifest.xml rather than more substantial changes and an additional BroadcastReceiver class. (2) The setup procedure is slightly more complicated using the home screen approach since you have to do more than just open the app, but not substantially more complicated. (3) The home screen approach does a better job of confining the user to the single app since he can't use the default home screen to launch other apps. Based on these results, I will probably use the home screen approach.


Solution

  • I'm currently engaged on a dedicated-device application and I can provide you a few details that might be useful.

    Listening to ACTION_BOOT_COMPLETED is the same as waiting for the device to finish it's boot, start it's Home application and then launch your app.

    I believe you don't want your final client to see a home screen and neither do I.

    You can, however, define your application as the HOME application of the Android device. As soon as it finishes it's boot, it will be the first visible application on the run.

    <activity....>
    <!-- Put this filter inside the activity you want to make the Home screen -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    

    Note: if you need your device to boot automatically when your dedicated-device turns on, try removing the battery from Android and connect it straight. This is not related to your question indeed but the way I see, might be helpful on your project.