I have developed an unity android application. I want to perform some action when app is in foreground and also in background. Right now i am trying to print log in several interval of time in recursive manner. I am using this method to call my countdown timer.
void OnApplicationFocus(bool hasFocus){
StartBattle();
isPaused = !hasFocus;
Debug.Log("isPaused " + isPaused);
}
void OnApplicationPause(bool pauseStatus){
isPaused = pauseStatus;
StartBattle();
}
And this method to print data in a recursive manner.
public void StartBattle(){
StartCoroutine(BattleRecursive(0));
}
public IEnumerator BattleRecursive(int depth){
// Start Coroutine"
yield return new WaitForSeconds(2f);
if (depth == 0)
yield return StartCoroutine(BattleRecursive(depth + 1));
if (depth == 1)
yield return StartCoroutine(BattleRecursive(depth + 1));
Debug.Log("MyCoroutine is now finished at depth " + depth);
}
Log is printing very well when app is in foreground, But when app is in background, it is not printing anything.