简体   繁体   中英

Tracking the activity life cycle

I have requirement wherein I have to display a lock screen if the user moves out of the application.

Hence, the structure is: Activity A extends Activity B. Wherein Activity B is the deciding activity : "was application in backgound". If so it launches the lock activity.

Now, say I am on activity A and receive a phone call. Hence the app gets into the background. When it resumes I can see the glimpse of Activity A for a fraction of second and then comes the lock activity.

Can there be any solution to avoid that glimpse of Activity A?

You can see the lifecycle of activity from official doc

You are using activity B just to track whether activity is alive. I am not sure if it is necesary.

If activity goes to background onPause() method is called, it means activity is not visible (it might be both screen lock or home button pressed), and onResume() is called when activity is visible again. In Activity A if you override onPause method and launch your lock activity, it should work. (Or set a boolean onPause and launch lock activity on resume(you might see Activiy A though)

Good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM