Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto start service in android?

Tags:

android

At Android application, it always extends Activity and the entry is onCreate. So it seems that user has to select application and click to luanch it.(if it is wrong,please advise me. sorry)

So, how to implent a service running on background without user clicking to start application?

like image 627
gsmaker Avatar asked Oct 26 '10 04:10

gsmaker


Video Answer


2 Answers

Use an IntentReceiver to receive the BOOT_COMPLETED_ACTION.

Then in the IntentReceiver, you can call startService().

like image 106
Randy Sugianto 'Yuku' Avatar answered Sep 19 '22 13:09

Randy Sugianto 'Yuku'


And when I install the applications apk on the emulator/device then the service will start running

That is not possible. Android does not allow applications of any form to run immediately upon installation.

like image 35
CommonsWare Avatar answered Sep 20 '22 13:09

CommonsWare