189 8069 5689

Android中应用前后台切换监听的实现详解-创新互联

前言

创新互联专注于企业成都全网营销推广、网站重做改版、海州网站定制设计、自适应品牌网站建设、H5网站设计商城网站建设、集团公司官网建设、成都外贸网站建设公司、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为海州等各大城市提供网站开发制作服务。

最近在工作中遇到了这么一个需求:如何实现 Android 应用前后台切换的监听?下面来一起看看详细的介绍:

iOS 内边是可以实现的,AppDelegate 给了一个回调监听:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
 func applicationWillResignActive(_ application: UIApplication) {
 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
 // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
 }
 func applicationDidEnterBackground(_ application: UIApplication) {
 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
 }
 func applicationWillEnterForeground(_ application: UIApplication) {
 // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
 }
 func applicationDidBecomeActive(_ application: UIApplication) {
 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
 }
}

分享文章:Android中应用前后台切换监听的实现详解-创新互联
当前网址:http://cdxtjz.cn/article/cccppe.html

其他资讯