-1

I am working on an AppLocker which is going to block access to other apps. It works fine when it's running but when I close it, clients will be able to have access to apps again, which means my app is useless.

I want to launch it on start up and keep it running, I would like to hide the on going notification icon.

Please guide.

Thanks alot

Toby
  • 9,696
  • 16
  • 68
  • 132
  • You want to start app on device restart? – Abdul Kawee Apr 25 '17 at 11:07
  • So what is the problem? Please look [here](https://stackoverflow.com/help/mcve) first – Denny Apr 25 '17 at 11:17
  • I guess the main concepts would be 1) running the app as a service (if not already done) 2) making sure that the service keeps running (see Koby's answer) 3) receiving a BOOT_COMPLETED broadcast with a broadcast receiver in your app. as described [here](https://stackoverflow.com/questions/2784441/trying-to-start-a-service-on-boot-on-android#5439320). – Markus Kauppinen Apr 25 '17 at 11:18
  • Thanks for ur fast answer, the broadcast reciever and boot completed are done but i heard that will works only when connecting device i want to lock apps and never close my app, i will try to create a service and set a sticky onStartCommande, will let u know. Thx – Abdou Maelaynayne Apr 25 '17 at 14:37

1 Answers1

0

"I want to lunch it on start up and keep it running" - You can't launch an app on startup, but you can keep it running in the background.

Use START_STICKY on an override of your onStartCommand function:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    handleCommand(intent);        
    return START_STICKY;
}
Koby Douek
  • 16,156
  • 19
  • 74
  • 103