[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
It turns out SystemClock.elapsedRealtime() is horribly wrong on a real device (or at least mine). After turning my phone off then running an app that just prints out the value for this, it came out to 870495360. On the emulator it's a much nicer number. Having said that, it still works fine if the Alarm is registered on BOOT_RECEIVED. On Mar 29, 9:22 am, AuxOne tyler.thack...@gmail.com wrote: I've done extensive tests and realized that the Alarm works perfectly when I install it to my device via Eclipse (then unplug the cable), but when I upload it to Android market the Alarm won't even start. Investigating further... -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
I'm starting the AlarmManager from a BOOT_RECEIVED broadcast and it works like a charm. I've noticed, however, that it requires a restart to take effect because it's triggered from a broadcast. In light of this I also start the AlarmManager from the onCreate() of my activity so that the user doesn't have to restart their phones, in this case it doesn't really work. I've read that Alarms/Services set from the Activity are destroyed when the Activity is. Is there some way around this? Perhaps have the Activity bounce a Broadcast off something such that the Service is not directly created from the Activity and thus doesn't get destroyed? Thanks -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: [android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
AuxOne wrote: I've read that Alarms/Services set from the Activity are destroyed when the Activity is. I don't know where you have seen that, but I am not aware of such a limitation. Got a link? The only times I know of when alarms get nuked are: -- on a reboot, all alarms go poof! -- if the user has a so-called task killer app and kills your app that way, your alarms go poof! (though alarms from other un-killed apps remain in place) -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Training in US: 14-18 June 2010: http://bignerdranch.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
It just occurred to me that if I create it from a static context it shouldn't really die with the Activity. That's what I used to be doing, but later I switched it to an instantiated class. I'll see what happens. On Mar 27, 9:12 am, AuxOne tyler.thack...@gmail.com wrote: I'm starting the AlarmManager from a BOOT_RECEIVED broadcast and it works like a charm. I've noticed, however, that it requires a restart to take effect because it's triggered from a broadcast. In light of this I also start the AlarmManager from the onCreate() of my activity so that the user doesn't have to restart their phones, in this case it doesn't really work. I've read that Alarms/Services set from the Activity are destroyed when the Activity is. Is there some way around this? Perhaps have the Activity bounce a Broadcast off something such that the Service is not directly created from the Activity and thus doesn't get destroyed? Thanks -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: [android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
AuxOne wrote: It just occurred to me that if I create it from a static context it shouldn't really die with the Activity. AFAIK, AlarmManager alarms are not dependent upon the particular component that created them. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 3.0 Available! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
Then maybe it's the Service that is dependent? All I know is it works after reboot, but not after immediately installing (and starting Alarm from Activity). It's a 1 hour+ timer. On Mar 27, 9:18 am, Mark Murphy mmur...@commonsware.com wrote: AuxOne wrote: It just occurred to me that if I create it from a static context it shouldn't really die with the Activity. AFAIK, AlarmManager alarms are not dependent upon the particular component that created them. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 3.0 Available! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: [android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
AuxOne wrote: Then maybe it's the Service that is dependent? All I know is it works after reboot, but not after immediately installing (and starting Alarm from Activity). It's a 1 hour+ timer. Like I said, I am not aware of any such limitation. As I wrote, the only times I know of when alarms get nuked are: -- on a reboot, all alarms go poof! -- if the user has a so-called task killer app and kills your app that way, your alarms go poof! (though alarms from other un-killed apps remain in place) Conversely, there are places in Android itself where AlarmManager is used from an Activity -- alarm clock and calendar, to name two. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 3.0 Available! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
I can't say I've had these problems with my code - I have the alarmmanager set to wake my app up every 'x' minutes (the pending intent kicks off a service) and from there I open an HTTP connection to a server. The server holds a PARTIAL wake lock so the phone doesn't go back to sleep immediately. Usually the phone will use the cellular network to make the connection as WiFi has probably gone to sleep and it takes a few seconds to wake- up/connect. In fact, my problem has actually been different, in that the HTTP request is dispatched via the cellular network, then (because it can) WiFi may come into service before the response has been received. Depending on timing, I've seen this situation break the cellular data connection, forcing my app to re-run the query. Doug On Mar 24, 8:51 pm, AuxOne tyler.thack...@gmail.com wrote: Just to let you know, I experimented with FULL_WAKE_LOCK. Not only did it not turn on the screen as it said it would, which is a good thing I guess, but it also doesn't seem to lock as effectively as the PARTIAL_WAKE_LOCK. Both seem to go into a deep sleep around 15-20 min of use and then WiFi connectivity is gone. When testing on the emulator faking a cellular network (and no Wifi), it works fine with PARTIAL so I didn't try FULL. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
So perhaps it would suffice to just Thread.sleep() for 30 seconds after WakeLock is set, to wait for the Wifi. I'll experiment with that. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
You need a partial wakelock and internet permission. On Mar 24, 3:56 pm, AuxOne tyler.thack...@gmail.com wrote: I have a Service/AlarmManager set to go off ever hour; as seen at:http://github.com/commonsguy/cw-advandroid/tree/master/SystemServices... The Alarm triggers a Socket connection to communicate with a Web Server. I'm logging the interaction to a file so I can see it later. When I leave the phone on my desk for a day, it seems that more often than not I get a Network unreachable error when trying to do any networking. I believe it is related to how deeply the phone goes into sleep. Is there a special kind of lock I have to hold, or some command required to prep the wireless radio so that it can be ready to access the Internet? Thanks. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
Thanks for your reply. I have the permission (it works on a short timer), and the WakeLock (as seen at the link in the OP). Perhaps I'm using the lock incorrectly? Could anyone confirm? Most of the lock code is here: http://github.com/commonsguy/cw-advandroid/blob/master/SystemServices/Alarm/src/com/commonsware/android/syssvc/alarm/WakefulIntentService.java Thanks again. On Mar 24, 5:12 pm, nikhil nik...@gmail.com wrote: You need a partial wakelock and internet permission. On Mar 24, 3:56 pm, AuxOne tyler.thack...@gmail.com wrote: I have a Service/AlarmManager set to go off ever hour; as seen at:http://github.com/commonsguy/cw-advandroid/tree/master/SystemServices... The Alarm triggers a Socket connection to communicate with a Web Server. I'm logging the interaction to a file so I can see it later. When I leave the phone on my desk for a day, it seems that more often than not I get a Network unreachable error when trying to do any networking. I believe it is related to how deeply the phone goes into sleep. Is there a special kind of lock I have to hold, or some command required to prep the wireless radio so that it can be ready to access the Internet? Thanks. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
The wi-fi lock sounds interesting, but I'd need it to work with the cellular network as well. Can I lock both? Actually, a lot of my testing is probably happening over wi-fi since for some reason my Dev 1 Phone doesn't like my ATT iPhone SIM card for data connections. Perhaps it really does work with cellular networks. Within the doWakefulWork function I instantiate a class and call one of its methods. It ultimately creates a new Thread to make the Socket connection. I guess that's the issue. Instead of releasing the lock at the end of WakefulIntentService.onHandleIntent, could I pass the lock into my Thread and release it from there? Your KungFu is the best! On Mar 24, 5:21 pm, Mark Murphy mmur...@commonsware.com wrote: AuxOne wrote: I have a Service/AlarmManager set to go off ever hour; as seen at: http://github.com/commonsguy/cw-advandroid/tree/master/SystemServices... That link looks strangely familiar... The Alarm triggers a Socket connection to communicate with a Web Server. The code you link to above uses an IntentService, so the service will shut down as soon as the work is done. Are you doing all your HTTP stuff within the IntentService's handler? I'm logging the interaction to a file so I can see it later. When I leave the phone on my desk for a day, it seems that more often than not I get a Network unreachable error when trying to do any networking. I believe it is related to how deeply the phone goes into sleep. Is there a special kind of lock I have to hold, or some command required to prep the wireless radio so that it can be ready to access the Internet? You can hold a WifiLock. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android 2.x Programming Books:http://commonsware.com/books -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: [android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
AuxOne wrote: The wi-fi lock sounds interesting, but I'd need it to work with the cellular network as well. Can I lock both? Cellular data should be always on, if I understand correctly. Within the doWakefulWork function I instantiate a class and call one of its methods. It ultimately creates a new Thread to make the Socket connection. Bt. I guess that's the issue. Ding, ding, ding! :-) Instead of releasing the lock at the end of WakefulIntentService.onHandleIntent, could I pass the lock into my Thread and release it from there? IntentService in general is not designed for you to fork other threads. Remember: the IntentService component will call stopSelf() as soon as onHandleIntent() returns, if there is no other Intent queued up to be processed. Since IntentService does its work (onHandleIntent()) in a background thread, I don't know why you're forking yet another thread. I'd just do the HTTP operations in doWakefulWork(). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Development Wiki: http://wiki.andmob.org -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
I have Threads because when the Alarm triggers I want to do two separate things, although they don't necessarily have to be at the *same* time so I'll remove the Thread. For the WiFi lock I'm acquiring and releasing two locks now. Is that about right? My WiFi lock looks like: PowerManager mgr = (PowerManager)context.getSystemService(Context.WIFI_SERVICE); lockWifi = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, LOCK_NAME_WIFI); lockWifi.setReferenceCounted(true); Thanks On Mar 24, 5:59 pm, Mark Murphy mmur...@commonsware.com wrote: AuxOne wrote: The wi-fi lock sounds interesting, but I'd need it to work with the cellular network as well. Can I lock both? Cellular data should be always on, if I understand correctly. Within the doWakefulWork function I instantiate a class and call one of its methods. It ultimately creates a new Thread to make the Socket connection. Bt. I guess that's the issue. Ding, ding, ding! :-) Instead of releasing the lock at the end of WakefulIntentService.onHandleIntent, could I pass the lock into my Thread and release it from there? IntentService in general is not designed for you to fork other threads. Remember: the IntentService component will call stopSelf() as soon as onHandleIntent() returns, if there is no other Intent queued up to be processed. Since IntentService does its work (onHandleIntent()) in a background thread, I don't know why you're forking yet another thread. I'd just do the HTTP operations in doWakefulWork(). -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android Development Wiki:http://wiki.andmob.org -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: [android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
AuxOne wrote: For the WiFi lock I'm acquiring and releasing two locks now. Is that about right? My WiFi lock looks like: PowerManager mgr = (PowerManager)context.getSystemService(Context.WIFI_SERVICE); lockWifi = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, LOCK_NAME_WIFI); lockWifi.setReferenceCounted(true); That looks strange. -- WifiLock is managed by WifiManager, which is not a PowerManager. -- WifiManager has a createWifiLock() method to create the WifiLock, not a newWakeLock() method Also, I'm not sure this is necessarily going to work if you are locking and unlocking at the time you are doing the WakeLocks. If your goal is for WiFi to be available immediately upon the alarm, you will need to use a WifiLock to keep WiFi active back when you schedule the alarm. To quote from the WifiLock documentation: Normally the Wi-Fi radio may turn off when the user has not used the device in a while. Acquiring a WifiLock will keep the radio on until the lock is released. Multiple applications may hold WifiLocks, and the radio will only be allowed to turn off when no WifiLocks are held in any application. If this is something that's supposed to be going on 24x7, since keeping the WiFi radio on all that time will drain the battery pretty good, I think you're more going to need to just hang tight in your doWakefulWork() until WiFi connectivity is restored. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Training in NYC: 10-11 April 2010: http://guruloft.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
If this is something that's supposed to be going on 24x7, since keeping the WiFi radio on all that time will drain the battery pretty good, I think you're more going to need to just hang tight in your doWakefulWork() until WiFi connectivity is restored. It is indeed 24x7. What do you mean by hang tight? Seems like no matter how long I wait the Wifi won't turn back on until the device fully wakes up, not your usual WakeLock state. The document does, in fact say, you have to keep the Wifi locked *before* it sleeps. That's pretty misleading considering a WakeLock doesn't have to be set before it sleeps, instead it wakes it up. Thanks for all your help. It sounds like there's no way to actual wake up Wifi. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: [android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
AuxOne wrote: If this is something that's supposed to be going on 24x7, since keeping the WiFi radio on all that time will drain the battery pretty good, I think you're more going to need to just hang tight in your doWakefulWork() until WiFi connectivity is restored. It is indeed 24x7. What do you mean by hang tight? Seems like no matter how long I wait the Wifi won't turn back on until the device fully wakes up, not your usual WakeLock state. Then grab a stronger WakeLock, I guess. The document does, in fact say, you have to keep the Wifi locked *before* it sleeps. That's pretty misleading considering a WakeLock doesn't have to be set before it sleeps, instead it wakes it up. Actually, it pretty much works as the name suggests. Thanks for all your help. It sounds like there's no way to actual wake up Wifi. Probably there is, but perhaps a partial WakeLock is insufficient. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Training in US: 14-18 June 2010: http://bignerdranch.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
[android-developers] Re: No Network Connectivity in Service/AlarmManager Process.
Just to let you know, I experimented with FULL_WAKE_LOCK. Not only did it not turn on the screen as it said it would, which is a good thing I guess, but it also doesn't seem to lock as effectively as the PARTIAL_WAKE_LOCK. Both seem to go into a deep sleep around 15-20 min of use and then WiFi connectivity is gone. When testing on the emulator faking a cellular network (and no Wifi), it works fine with PARTIAL so I didn't try FULL. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.