我有一个后台服务,它初始化system.net.mqtt库,并等待来自mqtt的消息。我有一个ptoblem的OnHandleIntent inizize图书馆和关闭服务!!在开机启动时,又没有接收到消息,为什么??
[BroadcastReceiver(Label = "StartReceiver", Enabled = true)] [IntentFilter(new[] { Intent.ActionBootCompleted })] public class StartReceiver : BroadcastReceiver { public override void OnReceive(Context context, Intent intent) { Toast.MakeText(context, "i got it " , ToastLength.Long).Show(); if (intent.Action == Intent.ActionBootCompleted) { var serviceIntent = new Intent(context, typeof(ServiceTermoCoperta)); serviceIntent.AddFlags(ActivityFlags.NewTask); context.StartService(serviceIntent); } } } [Service(Exported = true, Enabled = true)] public class ServiceTermoCoperta : IntentService { public IMqttClient clientMQTT; [return: GeneratedEnum] public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId) { base.OnStartCommand( intent, flags, startId); return StartCommandResult.Sticky; } protected override async void OnHandleIntent(Intent intent) { var mqttConfig = new MqttConfiguration { Port = 1883, MaximumQualityOfService = MqttQualityOfService.ExactlyOnce, KeepAliveSecs = 60, //WaitTimeoutSecs = 50, //ConnectionTimeoutSecs = 50, AllowWildcardsInTopicFilters = true }; clientMQTT = await MqttClient.CreateAsync("iot.pushetta.com", mqttConfig); new Handler(Looper.MainLooper).Post(() => { if (clientMQTT != null) { clientMQTT.ConnectAsync(new MqttClientCredentials("pusmdm476u47r", "xxxxxx", "aaaaaa")).Wait(); clientMQTT.SubscribeAsync("/pushetta.com/channels/tteste", MqttQualityOfService.AtLeastOnce).Wait(); clientMQTT.MessageStream.Subscribe(msg => { string bs = msg.Topic + " " + Encoding.Default.GetString(msg.Payload); //Send Data Intent localIntent = new Intent(Constants.BROADCAST_ACTION).PutExtra(Constants.EXTENDED_DATA_STATUS, bs); // Broadcasts the Intent to receivers in this app. SendBroadcast(localIntent); }); } }); } }
intentservice
属于计算服务,您可以使用它来完成需要很长时间的工作。
>
intentservice
将打开另一个不同于UI线程的工作线程来完成工作。
工作完成后,intentservice
将自动停止。
所以我建议您使用服务
来实现您的目标。
这是我第一次尝试android服务,所以我有点迷茫。我正在开发一个应用程序,需要一个服务在后台运行的所有时间。此服务是从主活动中的onclick事件初始化的。要启动服务,我使用以下代码: 在服务中,我基本上有两件事。在onCreate方法中,我初始化一个计时器,每隔30分钟它就打开一个新线程,并检查服务器是否有任何新数据。在onStart方法上,我注册了一个接收器。 谢谢
我正在开发一个应用程序,不断地从Kafka主题中读取数据。这些数据是字符串格式的,然后我将其写入xml文件 要编写这些文件,我使用执行服务。 我想知道什么时候应该关闭我的执行服务。如果我的应用程序是有时间限制的,我会在executor实例上使用它,但我的应用程序应该持续运行。 如果发生任何异常,我的整个应用程序被杀死,它会自动关闭我的执行者吗?或者我应该捕获一个未检查的异常并关闭我的执行器,就像我
我已经尝试了一段时间试图关闭ChromeDriver服务,但我无法开发如何关闭的解决方案。我正在使用摩卡和柴进行单元测试。第一个测试通过,第二个由于错误而失败。 我试着在selenium webdrive/chrome中查找。js模块,无法找到关闭服务的函数。我试着搜索答案,但在网上也找不到任何答案。也许我创建chrome驱动程序的方法需要重新设计。我尝试使用“selenium webdriver
我有一个声明为Spring托管服务的自定义注释: 但是,有些服务的bean定义在中。将添加到这些bean中,可以启用Autowiring并通过xml文件注入dependecy。
问题内容: 我是Web服务的新手。我想获得一个使用PHP的Web服务的良好教程和示例。请向我建议一些网站,以简单的方式解释这些事情。 谢谢… 问题答案: 以下是一些帮助您入门的链接: http://davidwalsh.name/web-service-php-mysql-xml- json http://www.ibm.com/developerworks/opensource/tutorial