0

I have an apk which runs only on background. I want it to start itself every X seconds.

I can do it from terminal with sh command:

#!/bin/bash
while true
do am start --user 0 -a android.intent.action.MAIN -n com.xxxxxxx/.MainActivity
sleep 20
done

But after reboot it stops running itself automatically. Besides, I don't want to use sh command everytime. So I decompiled the apk with apktool. What do I need to add to make our app start it self every x seconds?

p.s. I know that if I save the commands as sh file into etc/init.d/ it'll be persistent but I'm trying to learn how can we add it to source.

Varihlu
  • 57
  • 1
  • 9

1 Answers1

0

What do I need to add to make our app start it self every x seconds?

You need to schedule it with the AlarmManager. You can find more about that here.

But after reboot it stops running itself automatically.

You need to register a receiver for android.intent.action.BOOT_COMPLETED for you app to be invoked after boot. You can find an answer for that here. When your receiver is invoked, you can then again schedule your app for restarting.

Community
  • 1
  • 1
Sebastian
  • 1,076
  • 9
  • 24