c++ - Android NDK - Event for app enters background -
i know if there way identify app entered background ndk.
i have application spawns pthread with
pthread_create(&_thread, null, methodtocall, null); //create thread
now working fine. problem need thread run while app active. on ios not problem since created thread suspended system. on android continues run on lock screen until stop app.
this of course of study not battery life. know utilize jni phone call activities onstop() method. seems rather complicated.
so there improve way detecting within jni / c++ app has become inactive?
i think cannot access android app state c++ thread without using message passing function. since app suspends (when user closes app or screen) cannot pass messages android c++ thread.
i can think of 2 possible solutions might work you: 1. when activity "suspends" - "onpause()" method called, , there can "stop" thread or create sleep. in "onresume()" method can start 1 time again or wake up, depends on thread (how utilize it).
2.you can have flag checks whether app has suspended or not. create c++ thread sleep few seconds/milisecs , check flag - if flag on - stop thread, otherwise continue. in case can't wake thread, unless perform action similar first (make sleep/wakeup whenever app suspends/reactivates).
hope helps, tom.
android c++ multithreading android-ndk jni
No comments:
Post a Comment