Tag: intentservice

IntentService被系统杀死

我有一个应用程序,我可以提交一个服务器的时间状态。 为了节省电量,我将状态项列入SQLite Database ,并定期将JobScheduler提交给服务器。 插入项目的function如下所示: public synchronized void workThroughQueue() { try { for (QueueItem queueItem : getAllQueueItems()) { try { dao.insert(queueItem.getItem()); delete(queueItem); } catch (Exception e) { Log.e(TAG, “Queueitem konnte nicht verarbeitet werden: ” + e.getMessage(), e); } } } catch (Exception e) { Log.e(TAG, “Queueverarbeitung nicht vollständig: ” + e.getMessage(), e); } } 服务(kotlin): […]

如何使用Kotlin从Android中的IntentService发送通知

我是新的android开发,我想发送一个通知从IntentService当设备进入任何特定的地理围栏由用户设置。 我写了下面的代码发送通知。 class GeofenceIntentService : IntentService("GeofenceIntentService") { var notId: Int = 15452 override fun onHandleIntent(intent: Intent?) { var geofencingEvent = GeofencingEvent.fromIntent(intent) if(geofencingEvent.hasError()) { Log.e("JK–>>","geofencingError –>> "+geofencingEvent.hasError()) return } var geofenceTransition = geofencingEvent.geofenceTransition if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) { var pendingIntent = PendingIntent.getService(applicationContext,0,Intent(applicationContext,MainActivity::class.java),PendingIntent.FLAG_UPDATE_CURRENT) var notification = NotificationCompat.Builder(applicationContext).setAutoCancel(true).setContentTitle("Entered In Geofence!").setContentText("Click here for return to app!!").setContentIntent(pendingIntent).build() var notiManager: NotificationManager […]

IntentService(kotlin)的默认构造函数

我是新的Kotlin和intentService一点点堆栈。 清单显示我的错误,我的服务不包含默认的构造函数,但内部服务看起来不错,没有错误。 这是我的意图服务: class MyService : IntentService { constructor(name:String?) : super(name) { } override fun onCreate() { super.onCreate() } override fun onHandleIntent(intent: Intent?) { } } 我也尝试了另一个变种: class MyService(name: String?) : IntentService(name) { 但是当我尝试运行这个服务时,我仍然得到一个错误: java.lang.Class<com.test.test.MyService> has no zero argument constructor 任何想法如何修复Kotlin中的默认构造函数? 谢谢!