jjzjj

IntentService

全部标签

android - 停止 IntentService

有谁知道是否有一种方法可以在IntentService不完成其工作线程并自行停止的情况下停止它?简单的问题,但我在文档中找不到答案。有没有简单的方法来阻止它?谢谢 最佳答案 在向服务发送消息之前调用onStartCommand。转发消息进行排队。所以你可以重写onStartCommand,像这样:@OverridepublicintonStartCommand(Intentintent,intflags,intstartId){if(intent.getAction().equals("Stop"))stopSelf();onSta

android - 服务中的 BroadcastReceiver 不接收广播 Android

我有这个应用程序,用户在其中更新Activity中的某些变量,并且此Activity使用BroadcastReceiver将新变量传递给IntentService。但是,IntentService中的BroadcastReceiver似乎没有接收到广播。这是服务中用于创建广播​​接收器的代码protectedclassUpdateReceiverextendsBroadcastReceiver{@OverridepublicvoidonReceive(Contextcontext,Intentintent){Log.d("receiver","Gotmessage:");//state

android - 不同的 IntentServices 可以并行运行吗?

我在理解关于IntentServices的一条规则时遇到了一些困难。来自CreatingaBackgroundService:Workrequestsrunsequentially.IfanoperationisrunninginanIntentService,andyousenditanotherrequest,therequestwaitsuntilthefirstoperationisfinished.我不明白这是否意味着对同一个IntentService的不同调用,甚至是对不同IntentService的调用。帮助将不胜感激。 最佳答案

android - START_STICKY 用于 IntentService

我见过许多android服务示例,其中返回START_STICKY用于在启动时启动应用程序,但无论如何我可以对IntentService使用相同的示例。我知道Service方法在主UI线程上运行,而IntentService作为单独的线程运行。但是它们究竟如何被调用以及为什么无法在启动时启动IntentService。由于IntentService在单独的线程上运行,因此如果我不介意的话,我们可以更好地控制它。我尝试在IntentService中使用onStartCommand,但我的应用程序在启动时崩溃,即使它在手动启动时运行良好。我们可以覆盖IntentService中的onSta

android - IntentService - 查找队列中等待的 Intents 数量

在我的应用程序中,我使用IntentService来完成一些工作。我想知道有多少意向正在等待处理,因为IntentService将它们保存在“工作队列”中,并将下一个发送到onStartCommand()作为onStartCommand上一个已经完成。我怎样才能知道有多少Intent在这个“工作队列”中等待? 最佳答案 实际上这很简单:您需要做的就是覆盖onStartCommand(...)并递增一个变量,然后在onHandleIntent(...)中递减它.publicclassMyServiceextendsIntentServ

Android,当应用程序打开时显示 alertDialog 而不是通知

我关注了this开发人员教程,并按预期在我的应用程序中使用Geofencing。本地理围栏转换发生时,从IntentService中发送通知:@OverrideprotectedvoidonHandleIntent(Intentintent){GeofencingEventgeofencingEvent=GeofencingEvent.fromIntent(intent);...sendNotification(geofenceTransitionDetails);}privatevoidsendNotification(StringnotificationDetails){//Cre

android - 如何使 IntentService 的线程保持 Activity 状态?

我正在编写一个跟踪用户位置的测试应用程序。这个想法是我可以启动一个服务,然后注册位置更新。现在我为此使用IntentService。服务代码(不起作用...)如下所示:publicclassGpsGatheringServiceextendsIntentService{//varsprivatestaticfinalStringTAG="GpsGatheringService";privatebooleanstopThread;//constructorspublicGpsGatheringService(){super("GpsGatheringServiceThread");sto

android - 订阅或绑定(bind)到现有的 Intent 服务

我有一个应用程序有一个初始Activity,它在ListView中列出了一些文件。单击列表中的项目时,您会转到该特定文件的详细Activity。在详细View中,我有一个名为下载的按钮,当您单击下载时,它会启动一个IntentService,它会像这样设置要下载的文件:downloadButton.setOnClickListener(newOnClickListener(){publicvoidonClick(Viewv){Intentintent=newIntent(AppDetailsActivity.this,AppDownloadService.class);intent.p

android - 如何从 intentservice 开始 Activity ?

我有ServiceimplementsIntentService并且在OnHandleIntent中我想开始Activity。它不起作用:IntentdialogIntent=newIntent(this,typeof(Activity1));dialogIntent.AddFlags(ActivityFlags.NewTask);this.StartActivity(dialogIntent);我还能尝试什么?更新:AddFlags(ActivityFlags.NewTask);没用 最佳答案 IntentdialogIntent

android - 无法解析 Intent Service Android

我在尝试配置推送通知时遇到以下错误:06-0701:05:59.73518708-18708/com.ebr.apps.ebr.developmentE/FirebaseInstanceId:Failedtoresolvetargetintentservice,skippingclassnameenforcement06-0701:05:59.73518708-18708/com.ebr.apps.ebr.developmentE/FirebaseInstanceId:Errorwhiledeliveringthemessage:ServiceIntentnotfound.我在grad