我想调用start活动的广播接收器在android系统 [英] I want to call the start Activity in BroadcastReceiver in android
问题描述
我要调用的BroadcastReceiver开始活动的机器人。我知道这是一个服务,我们不能从一个服务调用的活动。
我要调用start活动的广播接收器在android系统。
块引用>呼叫
startActivity()
在上下文
传过来的参数。
我知道这是一个服务
块引用>A
广播接收器
不是服务
。
和我们不能从一个服务调用的活动。
块引用>是的,你可以叫
startActivity()
在服务
。但是,调用
startActivity()
,无论是从广播接收器
或服务
可能不是什么的用户的希望。你不知道什么用户在做,你可能会被接管的前景在别的中间。请只在地方使用,用户会看重中断,或提供替代品(例如,共享preference
来表示你应该使用通知
,而不是开始一个活动)。I want to call the start Activity in BroadcastReceiver in android. I know it is a service and we cant call an activity from a service.
解决方案I want to call the start Activity in BroadcastReceiver in android.
Call
startActivity()
on theContext
passed in as a parameter.I know it is a service
A
BroadcastReceiver
is not aService
.and we cant call an activity from a service.
Yes, you can call
startActivity()
in aService
.However, calling
startActivity()
from either aBroadcastReceiver
or aService
may not be what the user wants. You have no idea what the user is doing, and you might be taking over the foreground in the middle of something else. Please only use this in places where the user will value the interruption, or offer alternatives (e.g., aSharedPreference
to indicate that you should use aNotification
instead of starting an activity).这篇关于我想调用start活动的广播接收器在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!