Autorun A Delphi XE5 Firemonkey Android Application At Startup

Auto-Start At Boot Delphi AndroidWith the DOS operating system (OS), you could start an application on system start-up by adding the application to the autoexec.bat file. With the Windows OS, you could add it to the run key in the Windows registry. How do you get an Android application to automatically run when the device boots up? It can be done by creating a broadcast receiver that listens to the BOOT_COMPLETED broadcast intent. The steps necessary to create such a broadcast receiver with Delphi XE5 include:

  • create a new Delphi XE5 Android project
  • set uses permissions to receive boot completed
  • modify AndroidManifest.template.xml to let the Android system know you have a broadcast receiver
  • write some Java code
  • add it to the classes.dex
  • use this new classes.dex in your project
  • run the app on device

Click here to read the article, find out more about each of these steps, and get access to the source code link

NOTE: Be sure to read the tips section as there are some important bits of information that are a must read to ensure your Android application will run when your Android device starts up.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Autorun A Delphi XE5 Firemonkey Android Application At Startup by Delphi XE5 XE6 XE7 XE8 10 Seattle Berlin Firemonkey, Delphi Android, Delphi IOS is licensed under a Creative Commons Attribution 4.0 International License.

19 Responses to Autorun A Delphi XE5 Firemonkey Android Application At Startup

  1. David says:

    This article don’t work for me.

  2. Rubens says:

    I also could not , when I run the app it says the app has stopped or is not worked. Do you know if you have any video of the walkthrough that?

  3. Albert says:

    This dont work in Delphi 10 Seattle, any solution?

  4. Max says:

    Dont work in XE8. When I run the app it says the app has stopped or is not worked

  5. nolaspeaker says:

    For D10 Seattle, I had to update the build.bat significantly from the XE5 version to make the paths point to where the executables are now (very different)
    DannyWind’s XE6 demo works just fine after that.
    I made a new D10 app, followed all the instructions, and couldn’t make it autostart! Eventually, I simply overwrote the D10 app’s AndroidManifest.template.xml with the one from Danny being careful to replace the
    XE6 =
    with the
    D10=<receiver android:name="com.embarcadero.rtl.notifcations.NotificationAlarm" /
    Then it autostarted. I haven't yet figured out what was so different in the D10 manifest that prevented it from autostarting! ?

    • Pudnivec says:

      Can you please show us what changes you made in build.bat?
      It would be mean to me – I want to try it in Delphi Seattle 10 Update 1.

      Thank you.

      • nolaspeaker says:

        rem XE5 set ANDROID_JAR=”C:\Users\Public\Documents\RAD Studio\12.0\PlatformSDKs\adt-bundle-windows-x86-20130522\sdk\platforms\android-17\android.jar”
        set ANDROID_JAR=”C:\Users\Public\Documents\Embarcadero\Studio\17.0\PlatformSDKs\android-sdk-windows\platforms\android-22\android.jar”
        rem XE5 set DX_LIB=”C:\Users\Public\Documents\RAD Studio\12.0\PlatformSDKs\adt-bundle-windows-x86-20130522\sdk\build-tools\android-4.2.2\lib”
        set DX_LIB=”C:\Users\Public\Documents\Embarcadero\Studio\17.0\PlatformSDKs\android-sdk-windows\build-tools\22.0.1\lib”
        set PROJ_DIR=%CD%

        rem XE5 set EMBO_DEX=”C:\Program Files (x86)\Embarcadero\RAD Studio\12.0\lib\android\debug\classes.dex”
        rem —————————————————
        rem instead of merging with the Embarcadero base classes.dex…
        rem set EMBO_DEX=”C:\Program Files (x86)\Embarcadero\Studio\17.0\lib\android\debug\classes.dex”
        rem merge with the project’s classes.dex!
        rem careful with the steps: build, run bat, deploy the merged dex, not the original
        set EMBO_DEX=C:\Users\NolaSpeaker\Documents\Embarcadero\Studio\Projects\!RammTracker\Android\Debug\classes.dex
        rem —————————————————

  6. Pudnivec says:

    Are there some simpler solutions (for Delphi 10 Seattle – update 1) if I have created own function broadcast receiver?

    • nolaspeaker says:

      Not really, sorry. It’s a tricky business, but it can be done. Don’t forget: you must also modify the AndroidManifest.Template.xml

      • Jiri Paskevic says:

        You think that it’s tricky bussiness from EMBARCADERO?
        You know how to do it?

        • nolaspeaker says:

          “Tricky business” means “It is not easy to do”. But yes, I’ve done it with D10. I’ve already replied to other people’s questions with the hard parts. If you followed the DanyWind article, and make the changes for D10, then that’s a good start.

        • nolaspeaker says:

          Post a question on Stack Overflow. Link to it here, and I will answer it there.

  7. Pudnivec says:

    I had update build.bat from XE5 to D10 Seattle – update 1.

    The application works without any problems.
    Application opens automatically after reboot the system.

    The problem occurs when I add a background service to the application.
    Application can not run already in debug with error message ‘App has stopped’.
    What is wrong?

    • Pudnivec says:

      When I use the original version classes.dex as a background service application can run, but can not run again after rebooting the system. It’s a vicious circle.

    • nolaspeaker says:

      There are many things that could be wrong. I suggest you separate your booting problem from you services problem. Make an app without the booting changes. Then make the service, and sort out the issues there. When that is done, add the booting changes. I want to make a blog about what I did, but I can find nowhere I can share this info right?

  8. Richard says:


    Any idea what the new paths should be for Berlin? I have tried unsuccessfully to locate them

    • nolaspeaker says:

      Berlin upgrades the Seattle Java SDK installation, so my guess is the paths wouldremain unchanged. If you never had Seattle, then I imagine you would just update all the occurrences of “17” to “18” ie. “studio 17.0″becomes “studio 18.0”. If all else fails look for the executable that is being executed via the path setting. And set the path for that executable as appropriate in the batch file.

Leave a Reply

Show Buttons
Hide Buttons
Read previous post:
Delphi XE5 Firemonkey Gradients
Spruce Up Your Delphi XE5 Firemonkey Apps With Gradients

Paweł Głowacki says, on is Delphi Programming blog, "Everybody loves colors. Great apps should use colors in clever and original ways."...