- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
这就是我启动位置服务的方式。
private void initLocationService() {
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if(getPermissions(android.Manifest.permission.ACCESS_FINE_LOCATION,GET_LOCATION_PERMISSION)){
startService(new Intent(HomeActivity.this, LocationUpdateService.class));
}
}
在 LocationUpdateService
中,我将其作为 STICKY
服务启动。所以它一直在后台工作。
public class LocationUpdateService extends Service implements
LocationListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
IServiceResponse {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand: ");
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(BACKGROUND_INTERVAL);
mLocationRequest.setFastestInterval(BACKGROUND_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
由于我的应用当前针对 Api 25
(Nougat)
,我需要对此特定服务进行哪些更改才能使其在 Oreo
在使用 compileSdkVersion 25
时,我仍然无法访问 startForegroundService()
方法。
这些是我的 gradle
设置。
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 21
targetSdkVersion 25
}
最佳答案
startForegroundService()可从 API 级别 25
的 API 级别 26 NOT 获得。
把compileSdkVersion 25
和buildToolsVersion "25.0.3"
改成最新的试试。
例如,在我的例子中,我使用的是:
compileSdkVersion 26
buildToolsVersion '27.0.3'
关于android - 如果我的应用程序针对牛轧糖设备,startService() 是否仍然有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50562718/
Context.startService(intent) 和 startService(intent) 有什么区别,使用哪个有关系吗? 最佳答案 只有一个startService() 方法。 star
这只是一个知识问题,我知道这样做不是一个好的做法。所以这里是: 如果我调用 startService() 3 次而它已经在运行,我是否必须调用 stopService() 3 次才能让它停止? (它有
我有一个依赖 X 的 Windows 服务 S1。该服务是自动的,它可以毫无问题地启动。 此服务启动另一个具有相同依赖项 X 的服务 S2。问题是,当我调用 StartService() 启动 S2
我尝试从服务类启动 android 服务。这样做的原因是为了实现一些平台独立性。 这样做我在 android.content.ContextWrapper.startService(ContextWr
我有这个函数作为静态方法: public static void engine(SQLiteDatabase mydb){ Intent intent = new Intent
我在文档中的任何地方都找不到这个: 对 context.startService() 的调用是同步的还是异步的? 最佳答案 异步。它甚至不会开始做任何工作,直到您从您所在的任何回调(例如,onCrea
startService() 是创建一个新的服务实例还是使用现有的?例如,在下面的代码中,它是创建两个 UpdateService 实例还是只创建一个 UpdateService 实例?谢谢。
我正在尝试安装 Neo4j(1.8),但在启动服务时遇到问题。 解压zip文件后,我直接进入bin文件夹并执行批处理文件: Neo4J.bat install [SC] 创建服务成功 [SC] 启动
我正在 Delphi 10.2 pro 中编写一些服务应用程序,我想添加一个启动时间可控参数来强制服务应用程序进入启动等待循环足够长的时间,以便我可以单击进入“运行\附加到进程”窗口(在应用程序开始初
我有一个小脚本,用户可以在其中输入脚本名称(描述名称),并可以选择修改属性。这是通过GUI界面完成的:一个文本框和一些下拉列表。 我尝试了几种方法来实现它,但是没有一个起作用。 这是我如何检索服务信息
这件事让我非常头疼。 我正在尝试使用 CreateService 和 SERVICE_ALL_ACCESS 将驱动程序加载到进程中,在我实际尝试使用 StartService 启动服务之前,一切似乎都
这就是我启动位置服务的方式。 private void initLocationService() { locationManager = (LocationManager) getSyste
我已经创建了一个服务,我正在使用 bindService 函数通过我的 Activity 访问它,但我想在我的 Activity 退出后继续运行我的服务。 为此,我必须使用 startService,
我正在尝试在Windows 10(10.0.18362)上安装自签名内核驱动程序,这里是我遵循的步骤以及出现的错误。如何解决这个问题?谢谢 c:\>makecert -r -pe -ss Privat
我想从我的 Activity 类(class)中启动一项服务。问题是,onStartCommand 永远不会被调用。我在那里放置了断点,但它从未被击中。我的例子非常简单,我不明白为什么它不起作用。 M
我通过 Intent 在我的 Activity 和我的服务之间发送数据(我多次调用 startForegroundService 因为它再次调用 onStartCommand 并使用 getInten
这个问题已经有答案了: What is a NullPointerException, and how do I fix it? (12 个回答) 已关闭 6 年前。 我正在尝试使用 IntentSe
在 while(true) 语句中,我正在创建一个将在 onHandleIntent 中运行案例的 Intent 。但是,如果不将 Activity 类扩展到我的 LocationTracker 类,
我想用 C++ 程序启动卷影复制服务。这涉及获取服务控制管理器 (OpenSCManager) 的句柄,使用它来获取服务句柄 (OpenService),然后启动服务 (StartService)。
我继承了一个项目,但我不明白如何通过以下代码获得响应或设置回调: startService(new Intent(this, VenueUpdateService.class)); 目前,即使 Ven
我是一名优秀的程序员,十分优秀!