安卓手机软件开发需要什么知识,在什么平台上开发?
安卓手机软件开发需要什么知识,在什么平台上开发?我想参加一个安卓软件比赛,有C和C++基础,求指教
最满意答案
问题是UI只在run(event)循环转动时定期更新。 一个
for()
循环,我假设在主线程上运行,将阻止运行循环直到完成。 这不仅意味着进度条不会更新(或者更确切地说,最后会直接跳到100%),但是您可能会在一段时间内冻结UI。 (我假设,因为你正在显示一个进度条,这可能需要一段时间。)对于任何冗长的操作,您想要做的是在单独的队列/线程上完成工作,并定期调用主线程上的UI更新。 例如,您可能会尝试类似( 警告:在浏览器中键入 ):
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0); dispatch_async(queue, ^{ int j = 1000; for (int i=0; i<j; i++) { // Do your presumably useful work, not just looping for fun :-) dispatch_async(dispatch_get_main_queue(), ^{ // UI updates always come from the main queue! calculatingProgressBar.progress = (i/j); }); } });
此示例使用GCD( Grand Central Dispatch )。 你可以看到更高级别的结构,比如NSOperationQueue ,但基本思想保持不变。
如果您不熟悉并发(多线程)编程,那么您将获得适度的学习曲线以加快速度。 我建议从“ 并发编程指南”开始 。
The problem is that the UI is only updated periodically as the run (event) loop turns. A
for()
loop, which I am assuming runs on the main thread, is going to block the run loop until finished. Not only does this mean the progress bar won't be updated (or, rather, will jump right to 100% at the end), but that you are potentially going to freeze the UI for some time. (I assume, since you are showing a progress bar, that this could take a while.)What you want to do, for any lengthy operation, is to have the work done on a separate queue/thread, and call out the update the UI on the main thread periodically. For example, you might try something like (warning: typed in browser):
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0); dispatch_async(queue, ^{ int j = 1000; for (int i=0; i<j; i++) { // Do your presumably useful work, not just looping for fun :-) dispatch_async(dispatch_get_main_queue(), ^{ // UI updates always come from the main queue! calculatingProgressBar.progress = (i/j); }); } });
This example uses GCD (Grand Central Dispatch). There are higher level constructs you can also look at, like NSOperationQueue, but the basic idea remains the same.
If you are unfamiliar with concurrent (multithreaded) programming, you are going to have a modest learning curve to get up to speed. I suggest starting with the Concurrency Programming Guide.
相关问答
更多-
我假设您正在为您的数据使用模型和商店? 如果是这样,我建议你使用字段中提供的转换方法。 它允许您将该cat字段转换为tpl可以理解的更好的数据。 Ext.define('MyModel', { extend: 'Ext.data.Model', config: { fields: [ { name: 'cat', convert: function(values, record) { ...
-
循环中的Cocoa Touch ProgressView不显示更新(Cocoa Touch ProgressView in Loop not displaying update)[2023-05-31]
问题是UI只在run(event)循环转动时定期更新。 一个for()循环,我假设在主线程上运行,将阻止运行循环直到完成。 这不仅意味着进度条不会更新(或者更确切地说,最后会直接跳到100%),但是您可能会在一段时间内冻结UI。 (我假设,因为你正在显示一个进度条,这可能需要一段时间。) 对于任何冗长的操作,您想要做的是在单独的队列/线程上完成工作,并定期调用主线程上的UI更新。 例如,您可能会尝试类似( 警告:在浏览器中键入 ): dispatch_queue_t queue = dispatch_get ... -
好吧,看起来你不能在WatchKit应用中使用Cocoa Touch Framework。 我能够通过创建一个新的Watch Framework目标,然后将每个文件从原始框架分配到目标成员资格选项中的新框架来解决此问题。 这实现了我的目标,即在iOS和WatchKit之间共享代码而不会有重复的代码。 Okay, it looks like you cannot use a Cocoa Touch Framework inside of a WatchKit app. I was able to get ar ...
-
在源代码中使用cocoapods导入模块时,必须将其导入为 #import
而不是 #import "AFNetworking.h" Here's my pod file: source 'https://github.com/CocoaPods/Specs.git' pod 'AFNetworking', '~> 2.5' use_frameworks! You need to make sure you install the beta version of Coco ... -
真正的问题是结构的使用。 该结构只是一个快速的功能,与Objective-C不兼容。 可以在rintaro的帖子中找到解决方法。 在他的帖子的链接旁边,我希望你也像他一样提供有关该主题的Apple文档的直接链接。 The real problem is the use of the struct. The struct is a swift only feature and isn't compatible to Objective-C. A workaround can be found in the p ...
-
在大多数情况下,您可以在头文件中为类和协议使用前向声明,以避免循环导入问题(除了继承)。 在FRRViewController.h ,而不是导入FRRRotatingViewController.h ,您是否可以不进行前向声明? @class FRRRotatingViewController; You can use forward declarations for classes and protocols in headers in most situations to avoid circular ...
-
你为什么把[super init]语句放在初始化器的末尾? 子类化时,通常将此语句放在方法的开头。 对于UIView子类,在代码中创建视图时指定的初始值设定项是initWithFrame: ,所以您应该在添加标签和图像之前调用它。 您可以使用图像来计算自定义视图所需的框架。 -(CustomImageContainer *) initWithImage: (UIImage *)imageToAdd andLabel: (NSString *)text onTop: (BOOL) top atX: (int) ...
-
幸运的是,我认为你的问题没有任何硬性和正确的答案。 这取决于你想要做什么。 首先,不要篡改默认的Realm或默认的Realm配置,因为任何直接使用Realm的应用程序都可能会操作。 您还需要确保命名模型类型并将其从默认模式中排除。 (同样,您可能只想使用内部定义的模型的模式打开框架的领域。) 至于你的API,它看起来像是由你想在框架的上下文中使用Realm来决定的。 如果Realm是一个实现细节,那么控制用户如何通过API(如上所述的API)与基于Realm的对象进行交互是有意义的。 这样,您就可以精确控制 ...
-
一种方法是对您正在观看的变量使用Key-Value-Observing ,当它超过您的阈值时 - 显示您的UIAlertView。 One way is to use Key-Value-Observing on the variable you are watching, and when it crosses your threshold - present your UIAlertView.
-
使用hidesBarsOnSwipe更新ProgressView的约束(Updating Constraints for ProgressView with hidesBarsOnSwipe)[2023-10-21]
虽然可以通过代码实现自动布局约束,但使用组件(这里是SnapKit)使其更加简单: override func viewDidLoad() { super.viewDidLoad() [...] progressView.snp_makeConstraints { (make) -> Void in progressViewTopConstraint = make.top.equalTo(snp_topLayoutGuideBottom).offset(-2.5). ...