草庐IT

intentService

全部标签

android - 在 IntentService 中循环

我的IntentService中有一个无限循环,根据主Activity的输入每30秒更新一次我的View。publicclassIntentServiceTestextendsIntentService{StringTag="IntentServiceTest";StringACTION_RCV_MESSAGE="com.jsouptest8.intent.action.MESSAGE";publicIntentServiceTest(){super("IntentServiceTest");Log.d(Tag,"IntentServiceTestconstructor");}@Ove

android - 从 Activity 中停止 IntentService

我有一个IntentSerivce有时会在后台运行,在某些情况下它可能会运行很长时间。我为用户提供了一个退出应用程序的选项,它基本上只是停止并轮询并忽略任何GCM推送通知。但是,如果收到推送通知并且IntentService需要一段时间才能完成它必须做的事情(从服务器获取信息并在需要时向用户发送通知,例如新消息到达或东西)。这就是问题所在,如果用户在intentservice仍在运行时选择“退出”应用程序,他们仍然会收到我不想要的通知。我知道该服务有stopSelf()方法,但当我知道用户通过菜单按钮“退出”应用程序时,我需要在Activity中停止它。将另一个intent发送到服务不

android - 使用 IntentService 进行 MediaPlayer 播放

使用IntentService作为后台MediaPlayer按需播放是否合理?根据developer'sguideIntentService只有在实际工作时才会持续。考虑到每次我想再次播放轨道时重新初始化MediaPlayer所产生的开销,这似乎是个坏主意......所以我的问题是:使用这种服务实际产生的开销有多大。它会对系统/应用程序的性能产生明显的影响吗?我应该使用我自己的Service实现和专用工作线程吗? 最佳答案 IsitreasonabletouseanIntentServiceforbackgroundMediaPla

android - IntentService 响应死的 ResultReceiver

Activity实例化ResultReceiver并覆盖onReceiveResult。该Activity然后将Intent发送到IntentService并包含ResultReceiver作为额外的。一旦IntentService完成处理,它会将消息发送回ResultReceiver并在onReceiveResult中处理它。问题是,如果用户离开Activity,结果仍会发送回ResultReceiver,这会导致所有类型的问题。有没有办法阻止这种行为?我已尝试在Activity的onDestroy()中停止IntentService,但结果仍被发回。这是一个示例Activitypu

android - 来自 IntentService 的通知 - 获取上下文时出现 NullPointerException

我无法从IntentService生成通知(在通知区域)。我在获取NotificationManager时遇到了NullPointerException。问题出在Context上。06-0116:46:05.910:ERROR/AndroidRuntime(14745):Causedby:java.lang.NullPointerException06-0116:46:05.910:ERROR/AndroidRuntime(14745):atandroid.content.ContextWrapper.getSystemService(ContextWrapper.java:363)0

android - IntentService 的蓝牙连接问题

我需要通过蓝牙从我的Android应用程序传输一些数据(到Arduino)。我没有阅读/收到Arduino的任何回复。对于我的单线程需求,我选择了IntentService。配对后,我的代码在我第一次连接和发送数据时工作正常。我在无误发送数据后断开连接。但是当我第二次尝试连接时,我在尝试myBluetoothSocket.connect()时收到以下错误:readfailed,socketmightclosedortimeout,readret:-1唯一的解决方案是关闭Arduino设备电源并重新连接(如果我强制停止应用程序并尝试重新连接,这无济于事)。请注意,无论我连接和发送数据多少

android - HandlerThread 与 IntentService

我想请人解释一下,HandlerThread和IntentService之间的主要区别是什么,主要用例场景是什么?我知道HandlerThread包含一个Looper,它管理由Handler提供的消息队列。据我了解,您可以为HandlerThread推送任务,它将执行。它非常适合用于非UI相关的长时间运行的操作,您可以通过runOnUiThread()将结果推送回UI。相比之下,IntentService适用于长时间运行的非UI相关操作,可以按顺序执行任务,当它完成作业时调用selfStop()关闭自己完成。如果一个IntentService正在处理一个任务,当一个新的请求到达时,它会

Android IntentService 未启动

我知道这个问题已经被问过很多次了,但是所有其他线程根本没有解决我的问题,我看不出我的代码有什么问题。也许我在这里遗漏了什么,有人可以帮我吗?Intent服务的代码:packageServices;importandroid.app.IntentService;importandroid.content.Intent;importandroid.widget.Toast;publicclassWifiSearchServiceextendsIntentService{/***Aconstructorisrequired,andmustcallthesuperIntentService(S

android - 向 requestLocationUpdates intentService 发送额外信息会中断位置更新

我在使用传递给LocationServices.FusedLocationApi.requestLocationUpdates(GoogleApiClientclient,LocationRequestrequest,PendingIntentcallbackIntent)的PendingIntent发送额外字符串时遇到问题。看来我在Intent上添加的额外用户名正在破坏requestLocationUpdates试图移交给我的IntentService的位置>作为intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATI

android - IntentService 中的数据变化

我正在使用IntentService处理来自FCM推送通知的消息。当消息一个接一个地出现但设备未连接到网络时以及设备再次连接后FCM一次发送大量消息时,它可以按要求完美地工作,在这种情况下,服务在处理Intent数据时会导致一些歧义在调用Web服务时导致意外行为。我的推送通知消息处理程序类:publicclassPushMessageHandlerextendsFirebaseMessagingService{privatefinalstaticStringTAG="PushMessageHandler";@OverridepublicvoidonMessageReceived(Rem