开发者

Android - handle onPause, onStop in specific way

开发者 https://www.devze.com 2023-02-22 16:15 出处:网络
I need to log action in my app. Action is startApp, stopApp,开发者_如何转开发 pauseApp and resumeApp. Tricky part is that my approach is diffrent than standard Android way. When I say startApp I need

I need to log action in my app. Action is startApp, stopApp,开发者_如何转开发 pauseApp and resumeApp. Tricky part is that my approach is diffrent than standard Android way. When I say startApp I need start aplicaton, stopApp is when all Application goes background(ex. hit home button). Pause is when something force to pause App ( but don't want log when I lunch another activity from my app ). So startApp != onStart() , rather Application.onCreate(), stopApp != onStop() , pause != onPause() etc....

Has anybody idea how to handle this ?

I think about put KeyEvent on "Back Button" in first activity to determine if app is stop. But how about Home Button ? I can't use it the way I use "Back Button". How about pause ? I think about use standard onPause() and inside this method try to recognize if onPause() is invoke by my another Activity or by for example phone call. But how to recognize what invoke onPause ?

Thanks for any suggestions.


It's probably not a good idea to override what the home button does. Users will always expect it to do the same thing, so you want to keep that experience consistent.

I would recommend finding a way to do what you want to do within Android's given life cycle methods. So, in onPause you could use a flag of some sort to denote whether to do your own stuff or to handle the regular Android way. Does that make sense?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号