David E
David E

Reputation: 17

How to run a process on android at the time of .apk installation

I am writing an app that has a potentially long running and intensive process that needs to run once per install of my app. Is there a way that I can have something run this process while the .apk is being installed, or immediately after?

Upvotes: 1

Views: 188

Answers (1)

Jim
Jim

Reputation: 10278

You cannot run anything after JB until the user opens your app (for security reasons). You just need to ensure the user understands what is happening. Perhaps tell the user you will notify them when the app is ready or entertain them until the long running process is complete. You really have no other options.

Prior to that you could have a Broadcast receiver that listens for package updates with a negative priority and it would run after your app installed. Like this:

<receiver android:name=".InstallIntentReceiver" android:enabled="true">
            <intent-filter android:priority="-999">
                <action android:name="android.intent.action.PACKAGE_REPLACED" />
                <action android:name="android.intent.action.PACKAGE_INSTALL" />
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_CHANGED" />
                <data android:scheme="package" />
            </intent-filter>
        </receiver>

And in the receiver start a service that would do your long running process.

Upvotes: 3

Related Questions