android-service

How to detect key-guard state in android

你说的曾经没有我的故事 提交于 2019-12-01 05:29:17
问题 I have an application that requires to detect the previous state of the key-guard before calling disableKeyguard() or reenableKeyguard() , set by the user! is there any way of accomplishing this task? 回答1: From documentation Use ((KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE)).isKeyguardLocked() 来源: https://stackoverflow.com/questions/13986471/how-to-detect-key-guard-state-in-android

onStart() and onStartCommand() still called in 2.0 and higher

眉间皱痕 提交于 2019-12-01 05:19:51
According to this blog post and the documentation of onStartCommand() if you have a Service you should implement onStart() and onStartCommand() and in 2.0 and higher only onStartCommand() will be called. It seems that this is not the case and in my Service BOTH are being called. This was a problem as it was trying to do the work twice, so I had to add a check in onStart() to not do anything if the OS version was < 2.0. This seems like a hack and a bug. Anyone else experience this or do I maybe have something wrong? I cut and pasted the code right from the sample. @Override public int

How can I save data from Android service?

一笑奈何 提交于 2019-12-01 05:16:52
问题 I have a service that collects data, can I save the data in case of reboot or any other action that will restart the service, and how can I do it? 回答1: Can I save the data in case of reboot or any other action that will restart the service You will not necessarily find out when those sorts of events will occur. Save your data as you go. And how can I do it? Use a file. Or a database, which is a type of file. Or a SharedPreferences structure, which is backed by a type of file. 回答2: You may

postDelayed() in a Service

北城余情 提交于 2019-12-01 04:28:03
I'm trying to restart service from itself in a few time. My code looks like this (inside the onStartCommand(...) ) Looper.prepare(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(BackgroundService.this, BackgroundService.class); startService(intent); } }, 3 * 60000); Service is running in the foreground while this code executes, but it doesn't seem to call onStartCommand(...) . Is there any other way to restart service from itself in a few time? UPD: I've found out that it actually restarts service, but not in a

Is the Application class guaranteed to be instantiated before a defined boot receiver is called

我是研究僧i 提交于 2019-12-01 04:10:49
Excuse me for such an elementary question. I understand that the Application class is instantiated when my app's process starts and I understand when the phone is completed booting my boot receiver will be called. I'm assuming since the phone knows via the manifest that my app holds BOOT_COMPLETED intent filter, the reboot process is. Phone reboots, phone starts all processes with BOOT_COMPLETED, phone fires off BOOT_COMPLETED broadcast. My concern came from wondering if I reference Application class instance variables within my boot receiver if the receiver would ever get called before my

“Cannot perform this action on a not sealed instance” java.lang.IllegalStateException exception

柔情痞子 提交于 2019-12-01 04:06:51
With android AccessibilityService able to paste in other app EditText Field, but with browser testfields (Emulator Default Browser or Samsung deault Browser) its not working, throwing error: Cannot perform this action on a not sealed instance. In android chrome browser with some singnup textfield its working but not for all textfields. @Override public void onAccessibilityEvent(AccessibilityEvent event) { AccessibilityNodeInfo source = event.getSource(); if (source != null && ( event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED ) ) { // || event.getEventType() == AccessibilityEvent

How to correctly handle startForegrounds two notifications

大城市里の小女人 提交于 2019-12-01 03:48:28
I have an IntentService that uploads a file. Everything works fine, but I'm a little confused about how to handle the notifications. When I start the notification I use startForeground() because the files can be rather large and I don't want the upload to get killed unless absolutely necessary. When I use startForeground() it displays two notifications in the notification area (one under Ongoing and one under Notifications): I've read through a number of different Stack Overflow posts and web articles, but none of them answer the question I have...hopefully I haven't missed one that talks

Killing android application from task manager kills services started by app

試著忘記壹切 提交于 2019-12-01 02:56:56
问题 My application has one activity which starts two services but does not bind them. If I select return button to exit application (I cannot see it in task manager), both of the services started by application keep running. However, if I goto task manager and kill application, both of the services are stopped. I am not sure if it is intended behaviour but I want the services to keep running even after application exits. Any thoughts please. Thanks 回答1: That is the intended behavior of Task

onStart() and onStartCommand() still called in 2.0 and higher

别说谁变了你拦得住时间么 提交于 2019-12-01 02:51:23
问题 According to this blog post and the documentation of onStartCommand() if you have a Service you should implement onStart() and onStartCommand() and in 2.0 and higher only onStartCommand() will be called. It seems that this is not the case and in my Service BOTH are being called. This was a problem as it was trying to do the work twice, so I had to add a check in onStart() to not do anything if the OS version was < 2.0. This seems like a hack and a bug. Anyone else experience this or do I

postDelayed() in a Service

南楼画角 提交于 2019-12-01 01:57:28
问题 I'm trying to restart service from itself in a few time. My code looks like this (inside the onStartCommand(...) ) Looper.prepare(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(BackgroundService.this, BackgroundService.class); startService(intent); } }, 3 * 60000); Service is running in the foreground while this code executes, but it doesn't seem to call onStartCommand(...) . Is there any other way to restart