- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的应用程序中,我有 Activity A 和 B。在 Activity B 中,我想检查应用程序的空闲状态,如果用户没有交互或最小化应用程序几分钟意味着如何将其恢复到 Activity A。我不知道'知道如何找出应用程序的空闲时间。任何人都可以帮助我解决这个问题。
最佳答案
在 iOS 中:
1) 创建一个新文件 -> Objective-C 类 -> 输入一个名称(在我的例子中是 TIMERUIApplication)并将子类更改为 UIApplication。您可能需要在子类字段中手动输入。您现在应该拥有适当的 .h 和 .m 文件。
2) 在.h文件中
#import <Foundation/Foundation.h>
//the length of time before your application "times out". This number actually represents seconds, so we'll have to multiple it by 60 in the .m file
#define kApplicationTimeoutInMinutes 5
#define kMaxIdleTimeSeconds 60.0
//the notification your AppDelegate needs to watch for in order to know that it has indeed "timed out"
#define kApplicationDidTimeoutNotification @"AppTimeOut"
@interface TIMERUIApplication : UIApplication
{
NSTimer *myidleTimer;
}
-(void)resetIdleTimer;
@end
3).m文件
#import "TIMERUIApplication.h"
@implementation TIMERUIApplication
//here we are listening for any touch. If the screen receives touch, the timer is reset
-(void)sendEvent:(UIEvent *)event
{
[super sendEvent:event];
if (!myidleTimer)
{
[self resetIdleTimer];
}
NSSet *allTouches = [event allTouches];
if ([allTouches count] > 0)
{
UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
if (phase == UITouchPhaseBegan)
{
[self resetIdleTimer];
}
}
}
//as labeled...reset the timer
-(void)resetIdleTimer
{
if (myidleTimer)
{
[myidleTimer invalidate];
}
//convert the wait period into minutes rather than seconds
int timeout = kApplicationTimeoutInMinutes * 60;
myidleTimer = [NSTimer scheduledTimerWithTimeInterval:timeout target:self selector:@selector(idleTimerExceeded) userInfo:nil repeats:NO];
}
//if the timer reaches the limit as defined in kApplicationTimeoutInMinutes, post this notification
-(void)idleTimerExceeded
{
[[NSNotificationCenter defaultCenter] postNotificationName:kApplicationDidTimeoutNotification object:nil];
}
@end
4) 在main.m中
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "TIMERUIApplication.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, NSStringFromClass([TIMERUIApplication class]), NSStringFromClass([AppDelegate class]));
}
}
5) 在 appdelegate 中
#import "AppDelegate.h"
#import "TIMERUIApplication.h"
@implementation AppDelegate
@synthesize window = _window;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidTimeout:) name:kApplicationDidTimeoutNotification object:nil];
return YES;
}
-(void)applicationDidTimeout:(NSNotification *) notif
{
//revert to Activity A
}
希望这对您有所帮助....
关于android - IOS & android 如何获取应用程序的空闲状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16249395/
我有一个需要从远程下载数据的更新服务,但是就像微软的 BITS 我想在用户空闲和/或他们的网络利用率低时执行此操作,以免影响他们的体验. 我需要做什么或看什么?谁能指出我从哪里开始并获得我需要的信息的
我有一个运行良好的 Angular 项目,我正在实现 NG-IDLE 和 KeepAlive,以保持 session 新鲜并在 API session 到期之前注销用户。 我的问题是 ng-idle
我开始使用http://reactphp.org/用于处理 HTTP 请求。 我运行多个在不同端口上运行的 React Worker,然后使用 Nginx 作为负载平衡来处理请求。像这样 upstre
我有一个 ViewController,它将通过 init 请求访问位置服务 if ([CLLocationManager authorizationStatus] == kCLAuthorizati
1 S postgres 5038 876 0 80 0 - 11962 sk_wai 09:57 ? 00:00:00 postgres: postgres my_app
有没有办法在 Python 的 IDLE 中循环打开的窗口?似乎唯一的方法就是转到菜单栏,或者单击所需的窗口。谢谢。 最佳答案 在 Mac OS X 上,如果您使用的是来自与 Aqua Cocoa T
我在 java 中实现了一个邮件监听器,监听器进入 IDLE 直到新邮件到达,它打印电子邮件主题并立即再次返回 IDLE。 我是否有可能错过我发出的两个 IDLE 之间的事件(新电子邮件)? 例如,我
在嵌入式设备中,允许空闲 HTTP 连接保持打开状态的实际时间是多少? 我知道在 1999 年左右的互联网时代,互联网聊天室有时只会保持连接打开并在他们进来时发送回复。在那些日子里,HTTP 连接的空
我正在网页(在弹出窗口中)检查用户状态 - 他是活跃的还是空闲的。如果他空闲超过 30 分钟,窗口将自动关闭并重置数据库中的一些标志。 我设置了包含时间的 cookie(他打开弹出窗口的时间),并在每
我在空闲: >>> import mymodule >>> # ??? 导入模块后: if __name__ == '__main__': doStuff() 我实际上如何从 IDLE 中调用
除了 Sun Java Mail 之外,还有支持 IDLE 命令的 Java IMAP 库吗? 我一直在使用 Sun 的 JavaMail,它运行良好,只是它有相当多的内存开销。 最佳答案 Chilk
我尝试实现一个邮件服务器,使用 sun IMAPFolder 和空闲命令解析传感器发送的电子邮件。 不幸的是,空闲状态在30分钟后关闭并抛出FolderClosedException。为了模拟在空闲重
我有一个 PHP 脚本可以从文本文件中导入各种数据。 导入非常复杂,我的测试文件有 32.000 个条目。这些条目必须被解析并插入到 mysql 数据库中。 如果我要运行我的脚本,它需要 30 分钟才
我正在使用在后端使用 SQL Server 2008 的 Hibernate 开发 Spring REST Web 应用程序。我在 64 位 Windows 机器上使用 Tomcat 6 作为 Web
我对 JS 中的任务运行器非常陌生,这是我第一次尝试 GruntJS。在我的 Gruntfile.js 中,我保留了几个任务,例如 jshint、cssmin 等。我可以从命令行运行它们,但是当我在那
麦克:特立独行 python :3.4 我尝试在 Python 的 IDLE 中测试 timeit 模块 import timeit >>> timeit.timeit( "obj.method",
我的 C# 应用程序在系统启动时运行,必须等待本地 SQL Server 实例才能真正执行任何操作。现在,我只是等待服务器响应(我曾经获得服务的等待句柄,但那不可靠),然后启动应用程序的主对话框。 当
我在服务器上有一个 (bash) 脚本,我继承了它的管理方面,最近发现脚本中的一个缺陷,没有人引起我的注意。 发现问题后,其他人都跟我说这让他们很恼火,但从来没有告诉过我(太棒了。。。) 所以,脚本遵
假设我有一个 websocket 可以随时接收事件,但大部分时间处于空闲状态,初始连接后将消耗多少带宽以使其保持事件状态? 不管怎样,服务器是使用 ws 的 NodeJS,而客户端使用的是 QtWeb
当我打开应用程序时,让它在后台模式下运行很长时间,然后再次打开,然后不久又崩溃了。崩溃日志表明这次崩溃是由MapKit框架引起的。这只发生在设备中... . 有人能理解这个崩溃日志吗?请帮我解决这个问
我是一名优秀的程序员,十分优秀!