bindservice

startService与bindService的区别

こ雲淡風輕ζ 提交于 2020-04-24 03:32:21
Android执行Service有两种方法,一种是startService,一种是bindService。下面让我们一起来聊一聊这两种执行Service方法的区别。 1、生命周期上的区别 执行startService时,Service会经历onCreate->onStartCommand。当执行stopService时,直接调用onDestroy方法。调用者如果没有stopService,Service会一直在后台运行,下次调用者再起来仍然可以stopService。 执行bindService时,Service会经历onCreate->onBind。这个时候调用者和Service绑定在一起。调用者调用unbindService方法或者调用者Context不存在了(如Activity被finish了),Service就会调用onUnbind->onDestroy。这里所谓的绑定在一起就是说两者共存亡了。 多次调用startService,该Service只能被创建一次,即该Service的onCreate方法只会被调用一次。但是每次调用startService,onStartCommand方法都会被调用。Service的onStart方法在API 5时被废弃,替代它的是onStartCommand方法。 第一次执行bindService时,onCreate和onBind方法会被调用

Android: onServiceConnected not called after bindService

纵然是瞬间 提交于 2020-01-30 03:28:40
问题 None of the many similar questions I have found have helped to solve my issue. Here are some questions I've looked at: ServiceConnection.onServiceConnected() never called after binding to started service onServiceConnected never called after bindService method ServiceConnection::onServiceConnected not called even though Context::bindService returns true? OnServiceConnected not getting called Here is part of my android app code: //Local service interface private INetworkQueryService

Android: onServiceConnected not called after bindService

我怕爱的太早我们不能终老 提交于 2020-01-30 03:28:05
问题 None of the many similar questions I have found have helped to solve my issue. Here are some questions I've looked at: ServiceConnection.onServiceConnected() never called after binding to started service onServiceConnected never called after bindService method ServiceConnection::onServiceConnected not called even though Context::bindService returns true? OnServiceConnected not getting called Here is part of my android app code: //Local service interface private INetworkQueryService

Android Architecture Components: ViewModel/Repository vs bind to Service/IntentService

北战南征 提交于 2019-12-22 06:41:05
问题 I want to implement/refactor an app to the Android Architecture Components concept, see https://developer.android.com/jetpack/docs/guide In this topic Android Architecture Components ViewModel - communication with Service/IntentService, I found a very good answer to the architectural issue, see https://stackoverflow.com/a/46736146/6251815 But i want to ask, how to bind the service from a repository, because we have neither context nor activity here. To be clear on that, the question is about

Binding PlayerView with SimpleExoPlayer from a service

倖福魔咒の 提交于 2019-12-21 05:21:19
问题 I have implemented a Service to run the audio in background which runs perfectly but I am unable to get the instance of the SimpleExoPlayer from the service to the activity to update the UI and also the Audio plays twice in the background if I exit and reopen the activity. AudioPlayerService public class AudioPlayerService extends Service { private final IBinder mBinder = new LocalBinder(); private SimpleExoPlayer player; private Item item; private PlayerNotificationManager

Android Things with bindservice and kotlin - onResume and onPause Or Coroutines Or RxJava

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 17:19:25
问题 In this project: https://github.com/neuberfran/SmartDrive5, file: ModoComFirebase.kt I have issue BCM18 is already in use by PID, Because this gpio was opened in DriverService.kt file before. My question is: The Application class ModoAutomatico.kt has no methods onPause and onResume. How to use foreground service in this case to solve my Issue ? 回答1: The Application class ModoAutomatico.kt has no methods onPause and onResume. This is because the Application class is a singleton. It starts

Android AIDL的实现

心已入冬 提交于 2019-12-09 13:43:07
AIDL (Android Interface Definition Language) 是一种IDL 语言,用于生成可以在Android设备上两个进程之间进行进程间通信(interprocess communication, IPC)的代码。如果在一个进程中(例如Activity)要调用另一个进程中(例如Service)对象的操作,就可以使用AIDL生成可序列化的参数。 【一】AIDL文件的创建: AIDL使用简单的语法来声明接口,描述其方法以及方法的参数和返回值。这些参数和返回值可以是任何类型,甚至是其他AIDL生成的接口。 其中对于Java编程语言的基本数据类型 (int, long, char, boolean等),String和CharSequence,集合接口类型List和Map,不需要import 语句。 而如果需要在AIDL中使用其他AIDL接口类型,需要import,即使是在相同包结构下。AIDL允许传递实现Parcelable接口的类,需要import. 需要特别注意的是, 对于非基本数据类型,也不是String和CharSequence类型的,需要有方向指示,包括in、out和inout,in表示由客户端设置,out表示由服务端设置,inout是两者均可设置。 AIDL只支持接口方法,不能公开static变量。 其中AIDL的方法还提供了oneway这个关键字

[Android widget] Activity通过bindService启动Service...

核能气质少年 提交于 2019-12-07 10:15:20
Notification 就是在桌面的状态通知栏。这主要涉及三个主要类: Notification :设置通知的各个属性。 NotificationManager :负责发送通知和取消通知 Notification.Builder : Notification 内之类,创建 Notification 对象。非常方便的控制所有的 flags ,同时构建 Notification 的风格。 主要作用: 1. 创建一个状态条图标。 2. 在扩展的状态条窗口中显示额外的信息(和启动一个 Intent )。 3. 闪灯或 LED 。 4. 电话震动。 5. 发出听得见的警告声(铃声,保存的声音文件)。 Notification 是看不见的程序组件( Broadcast Receiver , Service 和不活跃的 Activity )警示用户有需要注意的事件发生的最好途径 下面主要介绍这三个类: 一、 NotificationManager 这个类是这三个类中最简单的。主要负责将 Notification 在状态显示出来和取消。主要包括 5 个函数: void cancel(int id) , void cancel(String tag, int id) , void cancelAll() , void notify(int id, Notification notification

Android Architecture Components: ViewModel/Repository vs bind to Service/IntentService

旧时模样 提交于 2019-12-05 09:53:50
I want to implement/refactor an app to the Android Architecture Components concept, see https://developer.android.com/jetpack/docs/guide In this topic Android Architecture Components ViewModel - communication with Service/IntentService , I found a very good answer to the architectural issue, see https://stackoverflow.com/a/46736146/6251815 But i want to ask, how to bind the service from a repository, because we have neither context nor activity here. To be clear on that, the question is about how to merge both concepts. What is my situation? I need to have a boundService (see https://developer

Binding PlayerView with SimpleExoPlayer from a service

瘦欲@ 提交于 2019-12-03 17:36:38
I have implemented a Service to run the audio in background which runs perfectly but I am unable to get the instance of the SimpleExoPlayer from the service to the activity to update the UI and also the Audio plays twice in the background if I exit and reopen the activity. AudioPlayerService public class AudioPlayerService extends Service { private final IBinder mBinder = new LocalBinder(); private SimpleExoPlayer player; private Item item; private PlayerNotificationManager playerNotificationManager; @Override public void onCreate() { super.onCreate(); } @Override public void onDestroy() {