I had a similar problem, and finally it was solved by writing a small singleton class in Java that runs the Python-4-Android binary from the SL4A installation in a subprocess created using java.lang.ProcessBuilder. Therefore, I donβt use SL4A mechanisms at all (triggers, upcalls, etc.), just borrowing Python.
This seems cleaner than trying to start and connect to a Python process through SL4A.
This is Python 2.7.1, cross-compilation extensions from Mac OS X Snow Leopard. My Python modules only do text input and output, accept socket connections, etc. No interaction with the Android API. All this works great: writing a Java stream to Python input and reading a Java stream to get Python output. Extensions C are built using P4A instructions . (Android could not find .so dynalibs until I added
[build_ext] inplace=1
to setup.cfg during build. I think this is because the install installation is never called on Android. I just press adb.
All states of the activity lifecycle seem to work, but I cannot yet determine whether the subprocess will automatically pause while the main process is in a stopped state.
I can post the code in a couple of weeks if that is interesting. (Only departure on vacation.)
My packaging plan is to put a ZIP archive of Python code in / assets and have an application for unpacking during the first onCreate. I have not implemented this yet, but I do not expect any problems.
source share