草庐IT

FOREGROUND_SERVICE

全部标签

android - RemoteServiceException : Context. startForegroundService 没有再调用Service.startForeground

我从DeviceMonitor得到以下异常输出://FATALEXCEPTION:main//Process:com.xxx.yyy,PID:11584//android.app.RemoteServiceException:Context.startForegroundService()didnotthencallService.startForeground()//atandroid.app.ActivityThread$H.handleMessage(ActivityThread.java:1881)//atandroid.os.Handler.dispatchMessage(H

android - 我想播放音频。我使用 Thread、AsyncTask 还是 Service?

我想在我的Activity中播放音频文件。我有三个按钮来控制媒体:播放/暂停/停止。此外,我还有一个媒体搜索栏,可用于前进/后退轨道。我尝试每1秒更新一次搜索栏进度。然后,我想到了Threads。这是正确的方向还是我需要考虑使用Services或AsyncTasks?MediaPlayer是否带有搜索栏?这对我有很大帮助。谢谢, 最佳答案 我会设置一个服务来控制媒体播放器,并设置一个AsyncTask来显示应用程序。让您的应用程序向服务发送消息以停止、启动(使用按钮的onClick),并在需要更新屏幕信息时获取当前位置信息。这将把播

android - 在单个进程中使用 AsyncTask(或 Timer)更好,还是在单独的进程中使用 Service 更好?

我刚刚读了AndroidArchitectureTutorial:DevelopinganAppwithaBackgroundService(usingIPC).基本上是让服务在单独的进程中运行。服务中将发生重复的计时器事件。在计时器事件处理程序中,它将执行网络以检索推文,并通知所有附加到它的监听器。监听器通过IPC附加到它。我可以看出这种方法有两个主要特征。推文检索操作在单独的进程中运行。它一直在运行,即使主要Activity已经退出。但是,如果“Italwaysrun”不是我的要求。当我退出主要Activity时,我希望一切都停止。如果我在主Activity中使用AsyncTask

使用 Service 或 IntentService 的 Android Client/Server Socket 通信

到目前为止,我能够在一个安卓设备(wifi网络共享/热点)上启动一个服务器,让客户端(另一个安卓)连接并向服务器发送消息。然后服务器回复了那个。我意识到我需要一种方法来保持服​​务器监听客户端,即使聊天应用程序没有运行。客户端应该能够发送消息并且服务器应该接收到它。我应该使用Service还是IntentService来实现它?我不能从AsyncTask和Service扩展...如何实现它?一些示例代码会很棒。这是我的服务器的样子:publicclassServerextendsAsyncTask{privateServerSocketserverSocket;privateTextV

java - Service.startForeground 震动设备

我正在使用startForeground()调用我的一项服务:NotificationCompat.BuildernotifBuilder=newNotificationCompat.Builder(this,"my_channel").setContentTitle("Loading");startForeground(1,notifBuilder.build());问题是,因为我正在使用我独特的通知channel并且它有振动:NotificationManagernotificationManager=(NotificationManager)context.getSystemSe

安卓开发 : Changing Screen Brightness in Service

现在我再试一次。我想改变屏幕亮度。我试过:WindowManager.LayoutParamslayoutParams=getWindow().getAttributes();layoutParams.screenBrightness=0.5F;//set50%brightnessgetWindow().setAttributes(layoutParams);并且似乎在Activity中工作,但是当我在服务中时,我得到了getWindow()编译错误。 最佳答案 服务不能那样改变屏幕亮度。服务没有用户界面,所以它没有Window。您

android - Service.onStartCommand() - 是否可以返回一个以上的标志?

我必须确保我的Service会运行,直到我显式调用stopService()。所以我应该从onStartCommand()返回START_STICKY标志。我还希望万一我的服务因为内存不足而被系统破坏,当系统重新创建它时-onStartCommand()将以最初启动服务的相同Intent被调用。因为这个原因-我想使用START_FLAG_REDELIVERY标志。根据文档-http://developer.android.com/reference/android/app/Service.html#ProcessLifecycle,我所描述的肯定会发生(并且实际上发生在我身上)我知道我

android - 语音识别器 : not connected to recognition service

在我的应用中,我直接使用SpeechRecognizer。我销毁了Activity的SpeechRecognizeronPause并在onResume方法中重新创建它,如下所示...publicclassNoUISpeechActivityextendsActivity{protectedstaticfinalStringCLASS_TAG="NoUISpeechActivity";privateSpeechRecognizersr;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedIns

android - getLayoutInflator 和 (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE) 有什么区别

我对这两种说法感到困惑。它们有什么区别,我什么时候可以使用它们?LayoutInflaterinflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);Viewv=inflater.inflate(R.layout.activity_custom_lists1,parent);和Viewv=getLayoutInflater().inflater.inflate(R.layout.activity_custom_lists1,parent); 最佳答案

并行运行的 Android Intent Service 工作请求

我创建了一个IntentService如下:publicclassOrdersSyncServiceextendsIntentService{privatestaticfinalStringTAG=OrdersSyncService.class.getSimpleName();privateOrderorderObject;publicOrdersSyncService(){super("OrdersSyncService");}@OverrideprotectedvoidonHandleIntent(Intentintent){//Util.showToast(getApplicat