jjzjj

IntentService

全部标签

Android:从 NotificationManager 操作 PendingIntent 调用 IntentService

我有一个推送通知应用程序。当推送通知到来时,BroadcastReceiver调用GCMIntentService设置通知mNotificationManager=(NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);Intentintent=newIntent(this,HomeActivity.class);Intentintent=newIntent(this,AddToCalendarIntentService.class);intent.putExtra(JSON_KEY_CLASS_

android - 使用bindService启动IntentService时是否应该调用onHandleIntent?

我的服务扩展了IntentService,当它用startService启动时,onHandleIntent被调用。但是,当使用bindService启动服务时(我确实需要绑定(bind)),onHandleIntent不会被调用。当IntentService被bindService启动时,是否应该调用onHandleIntent?startService是IntentService应该启动的唯一方式吗?IntentService的文档说明如下:客户端通过startService(Intent)调用发送请求;服务根据需要启动,使用工作线程依次处理每个Intent,并在用完工作时自行停止

android - 如何在有许多 IntentService 正在运行时停止一个 IntentService

我有一个包含很多歌曲的ListView。每次点击一首歌曲时,我都会调用一个IntentService来按顺序下载这首歌曲。但有时我想取消下载(例如:第5次)。这意味着我需要停止第5个运行的IntentService。我试图通过调用stopService()来停止它,但它不起作用。谁能告诉我停止IntentService的好方法?非常感谢您的帮助。 最佳答案 只有一个在运行IntentService,根据list中的元素。如果您调用startService()六次,最多一次IntentService将运行。命令将排队并由onHandl

android - 位置监听器从服务工作,但不是 IntentService

我有一个应用程序,我试图定期获取用户位置并发送到服务器。我有一个附加到AlarmManager的服务,它每分钟执行一次(用于测试)。该服务正确找到用户位置并注销GPS坐标。一旦有GPS锁定,我就会取消位置请求并停止服务。当我请求位置更新时,我启动了一个Handler,它会在20秒后执行,这个Handler会删除位置更新并停止Service以防万一没有实现锁定。所有这些都有效。下面是使用Service类的代码。publicclassTrackingServiceextendsService{privatestaticfinalStringTAG=TrackingService.class

java - 如何在 Android 中使用 intentservice 同时下载多个文件?

我想创建一个类似于此的服务(引用自Here),以在Android中异步下载多个文件。publicstaticclassDownloadingServiceextendsIntentService{publicstaticStringPROGRESS_UPDATE_ACTION=DownloadingService.class.getName()+".newDownloadTask";privateExecutorServicemExec;privateCompletionServicemEcs;privateLocalBroadcastManagermBroadcastManager;

android - 如何检查 IntentService 是否已启动

我想知道Activity是否成功启动了IntentService。由于可以通过bindService()绑定(bind)IntentService以保持其运行,也许一种方法是检查是否调用startService(intent)导致在服务对象中调用onStartCommand(..)或onHandleIntent(..)。但是我如何在Activity中检查它呢? 最佳答案 这是我用来检查我的服务是否正在运行的方法。服务类是DroidUptimeService。privatebooleanisServiceRunning(){Activ

Android - 多次运行 IntentService

所以我有一个IntentService,当我运行它一次时它运行良好。它对图像进行处理,然后输出一系列RGB值。但我现在需要它做的是多次运行以批处理出一系列图像。我的第一次尝试涉及在我的主类中调用停止服务,然后创建并运行IntentService的新实例。但是当我调用StopService时这崩溃了。有正确的方法吗? 最佳答案 IntentService在处理完所有请求后停止服务,因此您永远不必调用stopSelf()。IntentService无法并行运行任务,所有连续的Intent将进入消息队列并按顺序执行。因此,只需一个接一个地

Android 架构组件 ViewModel - 与 Service/IntentService 的通信

我正在探索Google的AndroidArchitectureComponents.在我的项目中,我依赖Services和IntentServices.与应用程序的ViewModel通信的正确方式是什么?来自IntentService或服务?使用LiveData可以实现吗? 最佳答案 TL;DR这是可以实现的——使用观察者关系。您的IntentService和可能的位置服务应该不知道您的ViewModel。考虑使用存储库。可以使用LiveData(参见postValue)。它有利于更新UI(ViewModel到Activity的通信

android - MediaPlayer 在单独的线程中使用 Service 或 IntentService

您好,我需要一个MediaPlayer实例在后台运行,所以我开始使用服务。一切正常,但一段时间后我收到ANR(应用程序未响应),即使UI运行良好。很公平,我知道服务仍在主线程上运行,所以ANR是有道理的。所以我尝试使用IntentService,它应该会生成自己的线程,但我除了头疼之外一无所获。当工作人员独立时,IntentService似乎没问题,但这里不是这种情况,因为每次我需要更改轨道时,我都需要从主应用程序调用startService(intent)方法,而且我不想以多个MediaPlayer实例结束在彼此之上玩耍..我还看到提示建议在服务中使用线程。我如何使用MediaPla

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