我想调用start活动的广播接收器在android系统 [英] I want to call the start Activity in BroadcastReceiver in android

查看:120
本文介绍了我想调用start活动的广播接收器在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 the Context passed in as a parameter.

I know it is a service

A BroadcastReceiver is not a Service.

and we cant call an activity from a service.

Yes, you can call startActivity() in a Service.

However, calling startActivity() from either a BroadcastReceiver or a Service 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., a SharedPreference to indicate that you should use a Notification instead of starting an activity).

这篇关于我想调用start活动的广播接收器在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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