Android的 - 如何开始同时服务和活动? [英] Android - How to start service and activity on same time?

查看:78
本文介绍了Android的 - 如何开始同时服务和活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一时间启动服务和活动。我现在用的是下面的code,这是正确的?

I want to start service and activity on same time. I am using the following code, It is correct?

startService(new Intent(this, Service.class));
Intent intent = new Intent(this, Activity.class);
startActivity(intent);

但这里的售后服务是complted则仅活动开始。为什么? 请帮助任何人。

But here after service is complted then only Activity starting. Why? Please help anyone.

推荐答案

有无从下手的活动和服务,在相同的过程中运行(这是默认行为)的同时,

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.

这篇关于Android的 - 如何开始同时服务和活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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