jjzjj

IntentService

全部标签

Android Service为IntentService扩展ResultReceiver,CREATOR如何实现?

我的应用依赖于在后台与外部硬件保持同步的Service。因为该服务在main线程上运行,所以它使用IntentService异步执行任何繁重的工作。这是解释控制流的代码的最小化示例:publicclassMyServiceextendsService{privatefinalHandlerhandler=newHandler();voidsomeMethodDoesCallBarAsynchronously(){Intenti=newIntent(this,MyIntentService.class);i.putAction(ACTION_FOO);i.putExtra(EXTRA_R

android - 如何使用 Notification.deleteIntent

我正在尝试检测我的通知何时被清除。我的问题直接引用这个answer这概述了我应该做的事情。这就是我执行这些操作的方式://usualNotificationinitializationherenotification.deleteIntent=PendingIntent.getService(context,0,newIntent(context,CleanUpIntent.class),0);notificationManager.notify(123,notification)这是CleanUpIntent类:classCleanUpIntentextendsIntentServi

android - 如何使用 Notification.deleteIntent

我正在尝试检测我的通知何时被清除。我的问题直接引用这个answer这概述了我应该做的事情。这就是我执行这些操作的方式://usualNotificationinitializationherenotification.deleteIntent=PendingIntent.getService(context,0,newIntent(context,CleanUpIntent.class),0);notificationManager.notify(123,notification)这是CleanUpIntent类:classCleanUpIntentextendsIntentServi

android - 如何使用 Robolectric 测试 IntentService?

我正在尝试使用Robolectric测试IntentService的onHandleIntent()方法。我开始使用以下服务:Activityactivity=newActivity();Intentintent=newIntent(activity,MyService.class);activity.startService(intent);ShadowActivityshadowActivity=Robolectric.shadowOf(activity);IntentstartedIntent=shadowActivity.getNextStartedService();asse

android - 如何使用 Robolectric 测试 IntentService?

我正在尝试使用Robolectric测试IntentService的onHandleIntent()方法。我开始使用以下服务:Activityactivity=newActivity();Intentintent=newIntent(activity,MyService.class);activity.startService(intent);ShadowActivityshadowActivity=Robolectric.shadowOf(activity);IntentstartedIntent=shadowActivity.getNextStartedService();asse

android - 即使应用程序关闭,如何保持 IntentService 运行?

在我的Android应用中,我通过调用从Activity中启动IntentServicestartService(newIntent(this,MyService.class));它就像一个魅力。我可以在Activies之间移动,按Home按钮切换到其他应用程序……它仍然可以工作。但是,如果我从最近的屏幕中删除我的应用程序,我的服务就会停止。我怎样才能避免这种情况?换句话说,即使我的应用已从最近的应用中关闭,我如何才能让我的服务继续运行?我的服务代码如下:publicclassMyServiceextendsIntentService{publicMyService(){super("

android - 即使应用程序关闭,如何保持 IntentService 运行?

在我的Android应用中,我通过调用从Activity中启动IntentServicestartService(newIntent(this,MyService.class));它就像一个魅力。我可以在Activies之间移动,按Home按钮切换到其他应用程序……它仍然可以工作。但是,如果我从最近的屏幕中删除我的应用程序,我的服务就会停止。我怎样才能避免这种情况?换句话说,即使我的应用已从最近的应用中关闭,我如何才能让我的服务继续运行?我的服务代码如下:publicclassMyServiceextendsIntentService{publicMyService(){super("

Android如何检查 Intent 服务是否仍在运行或已停止运行

我需要知道队列中的所有Intent服务是否都已“消耗”,或者另一种方法是确定它是否仍在执行某些操作,以便在所有服务停止运行之前我不会继续。有什么想法吗? 最佳答案 试试这个可能对你有用privatebooleanisMyServiceRunning(){ActivityManagermanager=(ActivityManager)getSystemService(ACTIVITY_SERVICE);for(RunningServiceInfoservice:manager.getRunningServices(Integer.MA

Android如何检查 Intent 服务是否仍在运行或已停止运行

我需要知道队列中的所有Intent服务是否都已“消耗”,或者另一种方法是确定它是否仍在执行某些操作,以便在所有服务停止运行之前我不会继续。有什么想法吗? 最佳答案 试试这个可能对你有用privatebooleanisMyServiceRunning(){ActivityManagermanager=(ActivityManager)getSystemService(ACTIVITY_SERVICE);for(RunningServiceInfoservice:manager.getRunningServices(Integer.MA

android - IntentService 创建的通知总是使用错误的 Intent

问题当用户按下发送“按钮1”(向下滚动查看应用程序的构造)时,新的Notification从RefreshService创建。如果用户按下此通知,则MainActivity实例将启动并收到StringIntent上的值Button1.显示此值。当用户现在按下Send"Button2"一个新的Notification从RefreshService创建。如果用户按下此通知,则MainActivity实例将启动并收到StringALSO与Intent上的值Button1.所以你可以猜到,通常应该有值Button2。当用户按下的第一个按钮是Send"Button2"时,总是会发送Button2