开发者

Global Listener in Android

开发者 https://www.devze.com 2023-04-11 08:19 出处:网络
I just wanna ask Are there any global listener that listens following in Andoird. The app is shut down. i.e the home or back key pressed.

I just wanna ask Are there any global listener that listens following in Andoird.

  1. The app is shut down. i.e the home or back key pressed. like what we have in iPhone SDK -(void)applicationWillTerminate:(UIApplication *)application

  2. When the app is crash due to uncaught exception.

  3. If 开发者_JAVA技巧the app went to background. The goToBackground or returnToForeGround listener. Just like what we have in iPhone SDK. -(void)applicationDidEnterBackground:(UIApplication *)application -(void)applicationWillEnterForeground:(UIApplication *)application Thanks


Points 1 and 3 are addressed by overriding onPause() method of an activity. This is automatically called by the framework when an application goes to background. You might be interested by this short introduction to activity lifecycle in android.

for point 2, you should take a look at the Thread.UncaughtExceptionHandler see this other question for use cases.

0

精彩评论

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

关注公众号