首页
\
问答
\
android.app.Fragment和android.support.v4.app.Fragment之间的区别(Difference between android.app.Fragment and android.support.v4.app.Fragment)
android.app.Fragment和android.support.v4.app.Fragment之间的区别(Difference between android.app.Fragment and android.support.v4.app.Fragment)
android.app.Fragment
和android.support.v4.app.Fragment
什么区别,以及每个应该使用的情况是什么?What is the difference between
android.app.Fragment
andandroid.support.v4.app.Fragment
, and what are the circumstances in which each should be used?
原文:https://stackoverflow.com/questions/15109017
更新时间:2023-11-12 11:11
最满意答案
您可以有任何类感兴趣的应用程序进入后台接收通知。 这是将这些类与AppDelegate耦合起来的好选择。
初始化所述类时:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
响应通知
-(void)appWillResignActive:(NSNotification*)note { } -(void)appWillTerminate:(NSNotification*)note { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil]; }
You can have any class interested in when the app goes into the background receive notifications. This is a good alternative to coupling these classes with the AppDelegate.
When initializing said classes:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
Responding to the notifications
-(void)appWillResignActive:(NSNotification*)note { } -(void)appWillTerminate:(NSNotification*)note { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil]; }
相关问答
更多-
在应用程序的Info.plist ,添加一个值为YES的布尔键UIApplicationExitsOnSuspend 。 有关详细信息,请参阅信息属性列表键参考 。 In your application's Info.plist, add a boolean key UIApplicationExitsOnSuspend with the value YES. See the Information Property List Key Reference for more information.
-
好的。 自从2天以来我一直在调查这个问题,终于找到了一个“狂野的方式”来解决它,而不会生根器件:) 首先,以下是实现解决方案的亮点: 1.每当用户进入设置 - >管理应用程序 - >选择一个特定的应用程序,我们收到一个广播android.intent.action.QUERY_PACKAGE_RESTART ,其应用程序的包名称作为附加。 2.之后,当我们点击卸载按钮(包装安装程序)时,它会打开一个名为 - com.android.packageinstaller.UninstallerActivity的活 ...
-
检测应用程序何时进入我的视图的背景是最好的方法?(What's the best way to detect when the app is entering the background for my view?)[2022-02-04]
您可以有任何类感兴趣的应用程序进入后台接收通知。 这是将这些类与AppDelegate耦合起来的好选择。 初始化所述类时: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] ... -
当应用程序进入后台并再次进入前台时,会调用onPause()和onResume()方法。 但是,当应用程序第一次启动并在其被杀死之前,它们也被调用。 您可以在活动中阅读更多内容。 在后台或前台没有任何直接的方法来获取应用程序状态,但即使我遇到了这个问题,也找到了onWindowFocusChanged和onStop的解决方案。 有关详细信息,请查看这里Android:解决方案,以检测Android应用程序何时进入后台并返回到前台,而无需getRunningTasks或getRunningAppProcess ...
-
你可以检测Android App何时进入后台?(Can you detect when Android App goes into background? [duplicate])[2024-03-01]
onPause()和onResume()是要覆盖的方法。 检查活动生命周期 onPause() and onResume() are the methods to override. Check the activity lifecycle -
比KVO更好的解决方案是在视图控制器中实现viewDidLayoutSubviews 。 一旦布局完成,就会在所有边界上进行更改。 A better solution than KVO would be to implement viewDidLayoutSubviews in your view controller. This is called on all bounds changes, once the layout is complete.
-
如果应用程序在ios应用程序中处于后台,如何检测推送通知?(How to detect push notification if app is in background in ios app?)[2024-01-17]
如果您的应用被杀或在后台,推送通知由系统管理。 可以唤醒您的应用程序的唯一一种推送是“ 无声推送通知 ”。 这解释了Apple内部文档 ,如果您需要在接收其中一个后在后台触发一些长任务,请记住创建后台任务。 也请查看此链接 。 Push notification are managed by the system if your app is killed or in background. The only kind of push that can wake up your app is a "sile ... -
检查您的窗口是否占据整个屏幕: BOOL isRunningInFullScreen = CGRectEqualToRect([UIApplication sharedApplication].delegate.window.frame, [UIApplication sharedApplication].delegate.window.screen.bounds); 如果为false =拆分视图或滑过。 检查 Check if your window occupies the whole screen: ...
-
iPhone应用程序进入背景状态并呈现UIAlertView(iPhone app entering background state and presenting a UIAlertView)[2023-11-27]
我有的最佳解决方案是保留对UIAlertView的静态引用,关闭(使用单击按钮索引-1),释放,然后在同一地址分配/初始化一个新实例。 这可确保只安排或显示一个警报视图。 如果已经显示警报视图,则忽略(或管理)新请求(故障安全弹出到根视图或某些此类视图)。 它不是很令人满意,因为UIAlertView与工作无关,不应该是静态的。 至少在我的脑海里。 The best solution I have is to retain a static reference to a UIAlertView, dismi ... -
您可以使用as运算符将Background强制转换为ImageBrush as并检查是否有空引用: ImageBrush brush = this.Background as ImageBrush; if(brush == null || brush.ImageSource == null) { //no ImageBrush set as the Background... } You could cast the Background to an ImageBrush using the as ...