首页 \ 问答 \ 安卓手机软件开发需要什么知识,在什么平台上开发?

安卓手机软件开发需要什么知识,在什么平台上开发?

安卓手机软件开发需要什么知识,在什么平台上开发?我想参加一个安卓软件比赛,有C和C++基础,求指教
更新时间:2023-12-19 21:12

最满意答案

问题是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) { ...
  • 问题是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.
  • 虽然可以通过代码实现自动布局约束,但使用组件(这里是SnapKit)使其更加简单: override func viewDidLoad() { super.viewDidLoad() [...] progressView.snp_makeConstraints { (make) -> Void in progressViewTopConstraint = make.top.equalTo(snp_topLayoutGuideBottom).offset(-2.5). ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)