android-service

Long running service consumes a lot of battery

一个人想着一个人 提交于 2019-12-21 11:13:08
问题 I developed an app and some people complains that it takes too much battery, it is the second most consuming process after the screen. However, in some devices it does not consumes that much battery. All the work my app do is in a service. The service is sticky and is running all the time (the android system may kill it when has low resources or pause it when device go to sleep), it has listener to the accelerometer as long as the screen is on, it is not foreground service and does not hold

How to ensure RemoteViewsService is run in the background in Oreo?

放肆的年华 提交于 2019-12-21 10:43:19
问题 Android 8 has its background execution limits, so when we started targeting Oreo we changed our services to using JobIntentSerivce to be able to get work done. However, we have a widget that updates every few minutes with live score data. The widget's service extends the good old RemoteViewsService. How can we make sure that the widget is updated even when the app is in the background? I've taken a look at the suggestions in another SO question, but they all seem to have some caveats:

How to ensure RemoteViewsService is run in the background in Oreo?

我是研究僧i 提交于 2019-12-21 10:43:06
问题 Android 8 has its background execution limits, so when we started targeting Oreo we changed our services to using JobIntentSerivce to be able to get work done. However, we have a widget that updates every few minutes with live score data. The widget's service extends the good old RemoteViewsService. How can we make sure that the widget is updated even when the app is in the background? I've taken a look at the suggestions in another SO question, but they all seem to have some caveats:

How to send an ArrayList of custom objects in a Bundle

大憨熊 提交于 2019-12-21 06:06:22
问题 I have an application that uses a service to create an ArrayList of custom objects (MyObject) every x seconds. I then want my Activity to obtain this ArrayList. I'm currently planning on having the Service send a message to the Activity's handler every time it finishes the query for the data. I want the message to the Handler to contain the ArrayList of MyObjects. When building the method in the Activity to get this ArrayList out of the message, I noticed that I couldn't. If I tried msg

Calling BroadCastReceiver from Service in android to Update UI in Fragment?

我的梦境 提交于 2019-12-21 05:57:06
问题 I want to update the UI of a fragment from service .I am using GCM for sending message.I have this class for GCM : public class GcmIntentService extends IntentService { public GcmIntentService() { super("GcmIntentService"); } @Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String

Calling BroadCastReceiver from Service in android to Update UI in Fragment?

萝らか妹 提交于 2019-12-21 05:57:01
问题 I want to update the UI of a fragment from service .I am using GCM for sending message.I have this class for GCM : public class GcmIntentService extends IntentService { public GcmIntentService() { super("GcmIntentService"); } @Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String

Handler.handleMessage is not called in test, but is called in the app

荒凉一梦 提交于 2019-12-21 05:37:16
问题 I have a service that runs in a separate process. The service spawns a new thread in onCreate() method. This thread sends messages back to the service. If I start the app manually everything works fine - messages are received by the Handler in my service. But in my test handleMessage() method is never get called. How can I fix my test to make handleMessage() method work? Thanks! Service: public class MyService extends Service { private ServiceHandler mHandler; private final int MSG_HELLO

Does an android widget run in the same process as it's app

风格不统一 提交于 2019-12-21 04:29:28
问题 I want to create a bound service for my app and would like it to be available for a widget to use in the future should i decide to create one. In order to decide whether to use a Messenger or extend Binder i need to know whether a widget and its corresponding app run in the same process? Thanks David 回答1: Yes. Unless you specify otherwise in the manifest (using android:process="..." ), all components of an application (widget providers, services, activities, broadcast receivers) run in the

binding to running Service (after finish() ) / callback Handler

爱⌒轻易说出口 提交于 2019-12-21 02:33:21
问题 Again a question about LocalServices. How do I (re-)bind to an existing Service, after onDestroy()? The Problem: I'm binding to a Service and Starting the service from an Activity. I'm Posting runnable Objects to the Binder, for a callback (updating a progressbar) on the UI. When I close this Activity, the OS could end the lifecycle and Destroy the Activity, calling onDestroy(), right? I simulate this, calling finish() in onPause() method. So once I restart the Activity, how to I bind to the

Using a wakelock in a service Android 1.5

淺唱寂寞╮ 提交于 2019-12-21 01:18:23
问题 Hello I am trying to use a service to control a wakelock so I can permanently leave the screen on when my application is running. I create the wakelock and activate it in onCreate() and release it in onDestroy() however I get the error "wl cannot be resolved". Can someone explain how I can get over this? Code below: public class WakeLockService extends Service { @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } @Override public void onCreate() {