内的应用程序,将在同一过程中的活性和服务运行? [英] Within an application, will the activity and service run in the same process?

查看:438
本文介绍了内的应用程序,将在同一过程中的活性和服务运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

专访问题:在应用程序中,将在同一过程或不同过程的活动和服务运行? 我的回答是:::在相同的过程。

Interview Question : With in an Application, will the Activity and Service run in the same process or different processes? My Answer was ::: In the same process.

下一个问题:::如果是这样,怎么是,活动和服务运行在同一时间? 我的回答是:::操作系统将执行的照顾。 (坦白地说,我不知道答案)。

Next Question ::: If so, how is that the Activity and Service run at the same time? My Answer was ::: Operating System will take care of the execution. (Frankly, I didn't knew the answer).

有人可以给上述问题的解释?如果我的答案是错的,什么是正确的答案?

Can someone give an explanation of the above questions? If my answer was wrong, what is the correct answer?

推荐答案

有无从下手的活动和服务,在同一个进程中运行(这是默认行为)在同一时间。

There is no way to start an Activity and a Service that run in the same process (which is the default behaviour) at the same time.

本服务的OnCreate()方法运行的主(UI)线程上的。

The onCreate() method of the Service runs on the main (UI) thread.

该活动的onCreate()方法也运行主(UI)线程上的。

The onCreate() method of the Activity also runs on the main (UI) thread.

有唯一的办法既开始更多或更少的同时是在一个单独的进程服务运行。

The only way to have both start at more-or-less the same time is to have the Service run in a separate process.

您可以尝试推出一些线程和使用旗语与barier标志。

You can try to launch few threads and use semaphore with barier flag.

这篇关于内的应用程序,将在同一过程中的活性和服务运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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