Issue
I want to use Application.ActivityLifecycleCallbacks
to monitor how many activities are there in the back-stack. Can I increment/decrement counter in onCreate/onDestroy to handle this?
Solution
Is onDestroy always called when android destroys activity to save memory?
Yes
Documentation:
The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish()
on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing()
method.
I want to use Application.ActivityLifecycleCallbacks to monitor how many activities are there in the back-stack. Can I increment/decrement counter in onCreate/onDestroy to handle this?
Better to counter in the onStart()
and onStop()
methods, onCreate() doesn't guarantee visibility. For example if somehow something stopped onStart()
from happening.
Answered By - Timmetje
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.