2

I would like to know if it is possible to run an android service in the background (and possibly on boot) without rooting the device, using python and sl4a and if so how would i go about doing that.

2 Answers2

1

For running a service in background or on boot you have to define a Broadcast Receiver which will basically start the service.

Please refer code snippets mentioned in the answer of below question.

Android BroadcastReceiver on startup - keep running when Activity is in Background

I have seen some information about developing in python on pythoncentral but I have never developed a service using python/sl4a.

Community
  • 1
  • 1
Hrushi
  • 153
  • 3
  • 13
  • The problem is that, that is coding in java and i have no experience in that i would prefer a more python solution. Although i am up for coding in java if you have some good starter guides i could quickly use to create this broadcast receiver – Daniel Prinsloo Aug 20 '14 at 18:32
  • I started learning Java for android and it is pretty easy to learn and develop. Specific to your question - I have already provided link in my answer.It has exact code for broadcast receiver on Boot that you'll need . Refer this tutorial on Broadcast receiver . http://www.vogella.com/tutorials/AndroidBroadcastReceiver/article.html – Hrushi Aug 20 '14 at 18:45
  • I can see Broadcast API in python documentation which does the same thing as Broadcast Reciever does. http://python-for-android.readthedocs.org/en/latest/android/ (search for Broadcast/android.broadcast) Hope this helps. – Hrushi Aug 20 '14 at 18:50
  • Thank you so much i will definitely be looking into that thank you – Daniel Prinsloo Aug 20 '14 at 18:53
1

If anyone is looking for a python for android (p4a) solution:

python-for-android supports the use of Android Services, background tasks running in separate processes. These are the closest Android equivalent to multiprocessing on e.g. desktop platforms, and it is not possible to use normal multiprocessing on Android. Services are also the only way to run code when your app is not currently opened by the user.

Gringo Suave
  • 29,931
  • 6
  • 88
  • 75