Android :: Service Seems To Sleep When Phone Is Inactive

Feb 7, 2009

I've written a test service to understand how android implements a service. I believe I understand the difference between Context.startService and Context.bindService. If I am not mistaken, Context.startService will tell android to keep this service running, even after the Activity that started it has ended.

While testing the service, I have come across something interesting.

My problem is that the service appears to sleep or pause for a few hours, run a short time, and then sleep for a few more hours, then run a short time, etc when the phone has become inactive. In other words, when I am doing things on the phone the service is doing what is is supposed to. But after I have finished doing things on the phone and the screen goes blank the service appears to sleep or pause. I don't know if I have implemented the service wrong or if this is how Android services work.

The test service I have written simply sets a postDelayed handler to increment++ a variable in the Runnable every minute, and then write the value of that variable and a timestamp to a file (log.txt) on the sd card. This how I know that the service appears to sleep. Because there are gaps in the timestamp that correspond to when the phone was inactive. If the service were truly active the whole time, there should be a line item in the log.txt file every minute.

From the log.txt file below you can see that over an eleven hour period there are only 36 line items with time stamps ranging from 10:27 PM through 9:23 AM. If the service was running and active the whole time there should be over 600 lines in the text file. The phone was on AC power the whole time so Android should not have tried to stop services due to power issues. The phone was not used or touched from about midnight to 9 the next morning, so there should not have been a low resource clean up.

I have spent several days looking for an answer and everything I can find seems to validate that when a service is started and not bound, it will stay running (http://code.google.com/android/reference/android/ app/Service.html). However, it appears it does not. Unless I have completely missed the ball on this.

I have included the service.java and activity.java as well as the log file.

Here is a sample log.txt

CODE:...............

Here is the service java file:

Java:

CODE:....................

Android :: Service seems to sleep when phone is inactive


General :: Sharing Connection From Android To Inactive Smart Phone?

Nov 26, 2012

I'm trying to share my 3g network from my straight talk LG Optimus zip my old sprint phone samsung galaxTr IPy s phone I have foxfi and pdanet on both phones can't find anything that works

View 1 Replies View Related

Android :: Way To Let Service Delay / Sleep?

Sep 24, 2010

I need to let service sleep for 0.5 sec just as using Thread.sleep(); is there any method??

View 1 Replies View Related

Android :: Service Application Not Working In Sleep Mode

Jan 26, 2010

I am using a service in my app. But it doesn't seem to work in sleep mode. I have implemented startforeground to prevent it from shutting down but it still does. Following is my code.............................

View 4 Replies View Related

Android :: Screen Was Black Case - Service Sleep

Sep 21, 2009

I wrote a service and I registered BroadcastReceiver in it. In the onReceive () method of BroadcastReceiver catagory,I just wrote Intent.ACTION_TIME_TICK.equals(intent.getAction()) to receive the systenm time every minute and deal with everything that I should do in it every minute.But i found a problem that when the mobile phone screen was locked and was completely black,my service seems to be sleep and does not work,and when I light up the screen(it is still in locked condition),the system will automatically run my service.I do not know the reason,I guess if it is because my service is not the system-level service? When the mobile screen is black,Andraid system will hibernate the sevice which is not the system-level service,so if this,I should add my service to system service,but I know how to use android.permission.ADD_SYSTEM_SERVICE? If you can,please send me a example about how to add own service to system-level service.This problem has been troubled me for two weeks.

View 2 Replies View Related

HTC EVO 4G :: Calendar Widget - Date Does Not Change When Phone Is Inactive

Jun 20, 2010

I have loaded the small calendar (HTC) widget on my home screen. Every morning when i turn on my phone the date on the widget is yesterday's date. When I set the time to 11:59PM the date changes when the clock changes to 12:00AM when the phone is active but the date does not change when the phone is inactive?

View 2 Replies View Related

General :: Print Text From Inactive Touch Phone?

Nov 2, 2013

I have an inactive t mobile my touch phone with text on it that i need to print out for a court case, but I no longer have t mobile service on this phone and have since switched to a S3 phone from a different carrier. How I can print the text out?

View 2 Replies View Related

General :: Tasker Profile Becomes Inactive After Phone Idle For 10 Minutes

Feb 11, 2014

I have an AT&T Samsung Note 3 SM-N900A running Android 4.3 (baseband version N900AUCUBMJ5, kernel v3.4.0-1625098). I rooted it using Kingo, installed Tasker (with Secure Settings plugin), and created 2 profiles: one with a 'Home' location context, and one with a 'Work' location context. In the 'Location Edit' map screen for each, I set a pinned location w/ a radius of 200m. I also de-select 'GPS' (leaving only 'NET'), since I don't want GPS enabled all the time (to extend battery life). I confirm that these work when I'm actively using the phone.. the profile becomes active when I'm at the specified location (as expected). I know it's active because it's displayed in the Notification Panel (and it's also shown in green in the Tasker profiles list).

The issue I'm having is that after ~10 minutes of idle time (i.e. when the display is off and I'm not using the phone), I find that the profile is no longer active when I turn the display back on and start using the phone again. I confirmed that this *doesn't* happen after 1 minute, 2 minutes, nor 5 minutes, only > 10. I also confirmed that it happens for both profiles consistently. However, as soon as I start Tasker again from the Apps Drawer (or from Recent Apps screen), the profile is immediately activated again, and my Enter task is re-run.

I enabled the run log in Tasker prefs, but it basically shows a clean activation of the profile (with no warnings or anything that looks weird to me).

I know there's a 10-minute timeout in the Display Off Monitoring prefs, but that doesn't seem to be related to my issue. I tried reducing the All Checks Seconds from 600 to 90, rebooted the phone, and it still took ~10 minutes before the profile would become inactive after the phone being idle.

View 1 Replies View Related

Sprint HTC Hero :: When Phone Is Inactive For While / Touch Screen Stops Working

Feb 23, 2010

Almost every day when I wake up I check my phone and 9 times out of 10 the touch screen does not work. I cannot make a call or check anything. I have to push a lot of buttons and take out the battery and generally wait a while before my expensive phone to start to work. Is there a fix for this? I've already had to go to sprit to do a hard reset because the phone got, "kicked off the network" for some reason the sprint people could not explain. Any solution for the screen issue?

View 4 Replies View Related

Android :: Set BroadcastReceiver To Be Inactive

Jun 22, 2010

I have a BroadcastReceiver set up in my Android application that receives SMS receive events. This works fine, but I want to be able to toggle SMS receiving on and off by toggling the BroadcastReceiver on and off. Because if I have a simple boolean inside the onReceive method, even if the SMS receiving is off, my application will start.

View 1 Replies View Related

Android :: Touch Screen Inactive

Nov 18, 2009

In stacking tasks, at some point the touch screen dont work any more. It works again later without reason. Is this a known problem ?

View 3 Replies View Related

Android :: Set An Image For Inactive Button?

Dec 15, 2009

I want to set a specific image when my button is not clickable. This button image is already selected according focused and pressed state thanks to this xml:

But I do not know how to define a new image for the button when it is not clickable.

View 1 Replies View Related

General :: Control Android Closing Inactive Apps?

Sep 17, 2013

I want certain apps (games etc) to be exempt from Android's auto closing algorithm, or at least be asked for permission when the system wants to close an inactive app. Is there any app that can do this?

View 1 Replies View Related

Android :: How To Know Phone Is Going To Sleep

Sep 16, 2010

How to know Android Phone is going to sleep? Help me with a sample code.

View 1 Replies View Related

General :: Internet Speed Goes To Zero When App Inactive

Feb 4, 2014

When I open browser(Boat browser or any other) and navigate to some url it works. Downloads are also working fine, but when i press 'home' button and go to home screen, the speed goes down to zero, but internet is connected. When I again switch back to browser, speed goes up.

This happens even when I lock screen. And even my gmail and google play apps are not working

Details
Motorola Atrix 2
Updated to ICS 4.0.4

View 1 Replies View Related

Android :: After 30sec Phone Goes Sleep

Jan 1, 2010

My problem is or has just started for some reason it was working fine yesterday. When i use my phone and then leave it alone 30 secs it goes into sleep mode and the lock is applied, now before i used to be able to push the menu or home button and the lock screen is displayed to which i can then swipe it down to unlock. This has stopped working all of a sudden, i press home or menu button and the lock screen will not swipe down to unlock the only way i can get into the phone is by pushing menu twice. I liked using the swipe down to unlock it. Is there any reason this has started to happen all of a sudden?

View 2 Replies View Related

Android :: Phone Sleep Function

Sep 16, 2010

I previously had a blackberry curve and loved the sleep function where phone would shutoff every night ay 10 and turn itself on at 6:00, is there an app/function for the droid where I can do the same?

View 1 Replies View Related

Android :: Does Youmail App Not Let My Phone Sleep?

Dec 28, 2009

Why does the youmail app not let my phone sleep? Background: Installed youmail app, realized battery was going FAST. Looked at awake time and it was 100%. Uninstalled all apps since the awake time debacle. awake time returns to normal. Re-install only youmaill app, awake time goes back to 100%. Go into preferences or settings, whatever and set for NO polling at all unless requested, no notifications, nothing. Awake time still 100%.Un-install youmail, awake time back to normal.I really like the app and the widget, someone tell me there is a way to fix this. I would like to re-install and use this app.

View 2 Replies View Related

Android : Run An App When Phone Is In Sleep Mode?

Jun 1, 2010

I'm developping a LiveWallpaper on Android 2.1. This application must download an image every fifteen minutes and draw it on the screen. Everything works except when the phone is in sleep mode. Do you think it is possible to run an application like this when the phone is in sleep mode? And if yes how?

View 3 Replies View Related

Android :: Check Phone Sleep Status

Jun 6, 2009

I'm trying to check if the phone is currently asleep in a service. It's currently a very messy implementation (I'm reading a file in the filesystem that says if the phone is asleep or awake every 10 seconds) so I'm wondering if this is possible with PowerManager or something.

View 3 Replies View Related

Android :: Network Access When Phone Sleep

Mar 21, 2010

I'm using a combination of alarm (set with AlarmManager) and background service to periodically synchronize data in my application. The only problem I have is that when sleep policy terminates Wi-Fi connection the synchronization no longer works. Is there a way to "wake up" the Wi-Fi connection that has been put to sleep? GMail somehow manages to do that because it notifies me about new e-mail even if the phone entered sleep mode.

View 2 Replies View Related

Android :: App That Can Turn Off Wifi Whenever Put Phone To Sleep?

Nov 2, 2010

Is there an app that can turn off my wifi whenever I put my phone to sleep? To conserve battery, I always have to turn off my wifi before I turn it off, and turn it back on when I unlock it. After a few days of this, it gets pretty annoying. I'm used to the iPod touch where when you sleep it, the wifi automatically turns off to save battery,and when you unlock it, and turns it back on. It would really save me the time.

Also I noticed this Wifi sleep policy thing. I don't really understand, can someone elaborate or explain more. Is it that when your not using your wifi for +15 min, it automatically turns off? Do you turn it on manually, or does it do it auto when you starting using wifi programs like browser.

View 10 Replies View Related

Android :: How To Detect Whether Phone Is In Sleep Mode In Code?

Mar 1, 2010

Is there any way to detect whether an android phone is in sleep mode (screen is black) in the code?I wrote a home screen widget. I don't want the widget gets updated when the screen is black to save the battery consumption.

View 1 Replies View Related

Android :: WiFi Disconnected When Phone In Sleep Mode?

Oct 6, 2010

I have a service which polls a server at certain intervals. I use an AlarmManager and a BroadcastReceiver to start the service. My problem is that after a certain duration, even though the WiFi is still enabled, but for some reason, my application can't contact the server. I get an "Unreachable network" error. Note that I've already acquired a partial wake lock as well as a wifilock. Here's my code for the BroadcastReceiver.

public class ServiceAlarmBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
WakeLock wakeLock = null; WifiLock wifiLock = null;
try { PowerManager pm = (PowerManager) context .getSystemService(Context.POWER_SERVICE);
// acquire a WakeLock to keep the CPU running
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
if(!wakeLock.isHeld()){ wakeLock.acquire();
} Log.i("ServiceAlarmBroadcastReceiver", "WakeLock acquired!");
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL , "MyWifiLock");
if(!wifiLock.isHeld()){ wifiLock.acquire();
} Log.i("ServiceAlarmBroadcastReceiver", "WifiLock acquired!");
context.startService(new Intent(context, ThePollerService.class));
} finally { // release the WakeLock to allow CPU to sleep
if (wakeLock != null) { if (wakeLock.isHeld()) {
wakeLock.release(); Log.i("ServiceAlarmBroadcastReceiver", "WakeLock released!");
} } // release the WifiLock if (wifiLock != null) { if (wifiLock.isHeld()) { wifiLock.release();
Log.i("ServiceAlarmBroadcastReceiver", "WiFi Lock released!"); } } } } }

View 2 Replies View Related

Android :: Code To Notify When Phone Screen Goes To Sleep?

Sep 18, 2010

I am an android developer I have a problem..
I want to be get notified when the phone screen goes to sleep Help with a sample code.

View 1 Replies View Related

Android :: Prevent Droid Phone From Going To Sleep Using My Code?

Sep 16, 2010

I want to prevent android phone from going to sleep using my code?
How to do that?

View 2 Replies View Related

Android :: Best Way To Schedule An Event That Will Wake Up Phone / Goes Into Sleep Mode?

Mar 2, 2010

I was investigating the issue of setting up a delayed activity/event, that will occur and trigger even if the phone is in sleep mode (wake up, do what you need to do, go back to sleep). I was thinking of the following methods: 1. sendMessageDelayed 2. Timer 3. AlarmManager.The basic requirement is to be able to set a triger in the future, and be sure that this trigger wakes up the system if it is sleeping,perform the task, and go back to sleep.A partial wakup is required (no screen flickering). Currently i'm using the sendMessageDelayed, and i keep a wake lock held for the timeout period (bad practice).

View 8 Replies View Related

HTC EVO 4G :: Phone Won't Sleep

Jun 9, 2010

Everytime i have checked my awake time and up time, they are the same! i don't know why! i have had an android phone since feb (had the hero) and it has never done this to me before.

rooted using unrevoked.
don't have wifi, bluetooth, or gps on.
when i check to see what's using my battery from the about phone->battery
-> Battery use i see this :
cell standby 23%
wifi 26% ( just realized it somehow got turned on through the day)
phone idle 24%
android system 12%
voice calls 9%
display 4%
dialer 2%

I can't think of anything else to mention, but PLEASE someone give me some advice as to what is making my phone stay awake!

View 9 Replies View Related

HTC EVO 4G :: Phone Does Not Sleep

Jun 15, 2010

When my phone is unlocked it stays unlocked with the screen on... did i change something somewhere?

View 4 Replies View Related

HTC EVO 4G :: Phone Not Going To Sleep

Sep 18, 2010

Ok well I just realised that my phone is dying rather quickly now and come to find out, my phone is not going to sleep for some reason. Never had this problem after 2.2 update and all the sudden it happens. Last thing I downloaded from market wad pdanet. Any ideas to what could be going on?

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved