如何开始从服务的活动? [英] How to start an Activity from a Service?

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

问题描述

是否有可能开始从服务的活动?如果是的话,我们如何才能做到这一点?

Is it possible to start an Activity from a Service? If yes, how can we achieve this?

推荐答案

android.app.Service 的后裔 android.app.Context 这样你就可以 startActivity 直接使用。但是,因为你开始这个你需要设置 FLAG_ACTIVITY_NEW_TASK 标志对意图的任何活动之外。

android.app.Service is descendant of android.app.Context so you can use startActivity directly. However since you start this outside any activity you need to set FLAG_ACTIVITY_NEW_TASK flag on the intent.

例如:

Intent i = new Intent();
i.setClass(this, MyActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

其中,为您服务。

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

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