什么是背后startActivityForResult()在Android的机制? [英] What is the mechanism behind startActivityForResult() in Android?

查看:154
本文介绍了什么是背后startActivityForResult()在Android的机制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动。在这个活动我要开始使用startActivityForResult()的另一个活动。据我所知,我的基本活动将启动一个进程中的一个主界面线程。 但据我了解,startActivityForResult()是asynchronious这意味着我的新活动将在不同的线程中执行。 我找不到里面关于线程的信息。如果只有一个GUI线程,如何这些功能的工作asynchroniously?

解决方案
  

不过,据我了解,   startActivityForResult()是   asynchronious这意味着我的新   活动将在被执行   不同的主题。

startActivityForResult()是异步的。这并不意味着你的新活动将在不同的线程中执行。如果新的活动是自己的应用程序的一部分,它运行在主应用程序线程,就像所有的其他活动。

  

如果只有一个GUI线程,请问这些功能的工作asynchroniously?

startActivityForResult(),像 startActivity(),不会立即做任何事情。相反,它把消息放在一个消息队列中,然后返回。当你控制返回到Android(例如,你的的onClick()方法结束),机器人可以追溯到处理邮件关闭该队列。当它到达您的启动活动的消息,就开始了新的活动。

I have an activity. In this activity I want to start another activity using startActivityForResult(). I understand that my basic activity is started within a process with a main GUI thread. But as far as I understand, startActivityForResult() is asynchronious which means that my new activity will be executed in a different thread. I can't find information regarding the threads inside. If there is only one GUI thread, how does these functions work asynchroniously ?

解决方案

But as far as I understand, startActivityForResult() is asynchronious which means that my new activity will be executed in a different thread.

startActivityForResult() is asynchronous. That does not mean that your new activity will be executed in a different thread. If the new activity is part of your own application, it runs on the main application thread, like all your other activities.

If there is only one GUI thread, how does these functions work asynchroniously ?

startActivityForResult(), like startActivity(), does not do anything immediately. Rather, it puts a message on a message queue, then returns. When you return control back to Android (e.g., your onClick() method ends), Android goes back to processing messages off of that queue. When it gets to your start-activity message, it starts up the new activity.

这篇关于什么是背后startActivityForResult()在Android的机制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆