[android-developers] Re: Unpublishing an APK
>>>>> "d" == dashman writes: d> The OPs problem seems to be solved and maybe answered. d> So...mini-hijack. d> what version control system is recommended - i.e. works with eclipse I'm a CVS kind of guy. Been using it for years and it has great Eclipse integration. More modern developers would probably go for Subversion over CVS. -- Jake Colman -- Android Tinkerer -- -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] Setting LED on a Notification
This should be simple but I can't get it to work. My application is triggering a notification. I want that notification to make s aound, vibrate, and turn on the LED. It all works but the LED. My code does something similar to the following: Notification X = new Notification(...); X |= Notification.DEFAULT_SOUND; X |= Notification.DEFAULT_VIBRATE; X |= Notification.DEFAULT_LIGHTS; I also tried the following in lieu of setting the default: X.flags |= Notification.FLAG_SHOW_LIGHTS; X.ledOnMS = 1; X.lefOffMS = 0; None of this is working to get the LED to flash. Am I missing something totally obvious? -- Jake Colman -- Android Tinkerer -- -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] null Intent in onStartCommand
According to the docsou can get a null intent if the service is restarted by Android. Simple question: do I just ignore the intent since I can't do anything with it anyway? Am I supposed to know what to do with it? If not, why does Android bother doing it? -- Jake Colman -- Android Tinkerer -- -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] Re: Unpublishing an APK
>>>>> "T" == TreKing writes: T> On Sat, Feb 2, 2013 at 8:08 PM, Jake Colman wrote: >> I uploaded a new APK and discovered a bug a stupid oversight (I >> forgot to turn off my debug flag). >> T> You no longer have to manually change the debug flag. Just omit T> it. When your run through Eclipse (using the debug certificate) T> it's enabled by default. When you export for release, it's T> disabled for you. This was an application-level debug flag that I use for things like controlling whether the app should update my Flurry statistics. I accidentally uploaded the debug version that did not invoke the Flurry API. I needed to reset the flag and reupload the app. >> This got me thinking whether there was a better way to handle >> this. What do I do if I upload a bad APK but need a few hours or >> days to fix it? >> T> Revert to your last good build in your version control (you do T> have version control, right?), update version code, re-release. Yes to version control. Been a developer for many, many years and would never work without it. In this instance I was able to quickly fix my problem and upload a new version. I changed the version code but kept the same version name. >> Is there a way to remove the latest APK and restore the APK that >> was prior to it? >> T> The developer console has this nifty notion of "active APK" and T> buttons that read "set as active" (at least the old console T> did). This might lure you into thinking that you can just push a T> button and go back to a previous version. You actually can't and T> this idea of "active APK" turns out to be utterly pointless and T> begs the question of why it was ever even put there in the first T> place. >> It see the "unpublish" option that I think that would remove the >> entire app from the store. >> T> Correct. You don't want to do that. Amazing. You would think that you could tell Google to ignore the latest APK and reactivate the one before it. Since you cannot, the only option is what you suggested - revert from version control and upload yet another APK. Thanks. -- Jake Colman -- Android Tinkerer -- -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] Unpublishing an APK
I uploaded a new APK and discovered a bug a stupid oversight (I forgot to turn off my debug flag). I quickly fixed it, updated the manifest with a new version code (but kept the same version name) and uploaded a new APK. Elapsed time from the mistake until the correction was about 5 minutes. I am assuming that since the bad version was only there for minutes no one will ever get to download it. This got me thinking whether there was a better way to handle this. What do I do if I upload a bad APK but need a few hours or days to fix it? Is there a way to remove the latest APK and restore the APK that was prior to it? It see the "unpublish" option that I think that would remove the entire app from the store. -- Jake Colman -- Android Tinkerer -- -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] Re: AppWidgetProvider onDeleted vs onDisabled
>>>>> "T" == TreKing writes: T> On Tue, Jan 29, 2013 at 10:51 AM, Jake Colman wrote: >> I am finding that, on occasion, after I delete my widget from my >> homescreen the underlying Service that I use is still receiving >> alarms and doing work. I do all my clean-up in onDisabled and do >> nothing on onDeleted. Is it possible that onDeleted can be called >> without an intervening call to onDisabled? >> T> You've verified that the method is definitely not being called? It T> could be that it's being called and you have a bug, like not T> deleting the correct alarm or something. T> Also, if you're cleaning up a single instance, I think you should T> use onDeleted. onDisable is for when there are no widgets at all T> left and you need to clean up some shared state or something. I am doing my clean-up in onDisabled since I only need to clean up after the last widget is removed. Under normal circumstances, when I remove the widget onDeleted fires followed by onDisabled. In the following scenario I get screwed: 1) Press on homescreen to install the widget 2) Configuration activity is displayed. Press back arrow to exit. 3) On CM7 (my test phone) the "resize widget" activity is displayed. Instead of pressing "OK", press back arrow. The widget is NOT created. In this instance, if I create another widget and delete it only onDeleted is fired but onDisabled is not. It looks like Android thinks that the first aborted instance is still there. How can I protect against this scenario? -- Jake Colman -- Android Tinkerer -- -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] AppWidgetProvider onDeleted vs onDisabled
I am finding that, on occasion, after I delete my widget from my homescreen the underlying Service that I use is still receiving alarms and doing work. I do all my clean-up in onDisabled and do nothing on onDeleted. Is it possible that onDeleted can be called without an intervening call to onDisabled? -- Jake Colman -- Android Tinkerer -- -- 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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] Re: Application.onCreate Method Randomly Called?
Thanks, Mark, for your help. Bottom line: I am not guaranteed that onDestroy() will be called before another invocation of onStartCommand(). It never occurred to me that was possible. I'll apply() my changes every time the key is modified. Thanks. >>>>> "MM" == Mark Murphy writes: MM> On Fri, Jan 18, 2013 at 11:42 AM, Jake Colman wrote: >> The key is committed in the Service's onDestroy method. MM> Please apply() the change when you make it. onDestroy() is not MM> always called on components. >> The Service is started by my AppWidget every time the app widget >> needs to do some work. I do not explicitly stop the Service, >> relying on Android to stop it if/when needed (that is not bad >> practice as I understand it). MM> Correct, but then onDestroy() is not necessarily called. Please MM> apply() the change when you make it. >> In other words, would multiple calls to Application.onCreate cause >> the Service.onCreate to be called a second time without an >> intervening Service.onDestroy? MM> Yes, if onDestroy() was not called on the service. >> If this is the problem, is it expensive to persist a key as soon >> as it is changed? MM> It is equally as expensive as doing it in onDestroy(), because it MM> is the same code. Using apply() does the save in a background MM> thread. >> Or should calls to commit be bundled and done as infrequently as >> possible? MM> Things that you do not apply() are not persisted. You need to MM> persist them at some point and feel confident that "some point" MM> will be reached. MM> Persistence involves disk I/O. Doing a million disk I/O MM> operations is more expensive than doing one. Hence, to some MM> degree, "bundling" may be useful. Only you can draw the line at MM> where you cannot afford to lose data. This is no different than MM> choosing appropriate transaction bounds in database operation. MM> -- MM> Mark Murphy (a Commons Guy) MM> http://commonsware.com | http://github.com/commonsguy MM> http://commonsware.com/blog | http://twitter.com/commonsguy MM> Aqui estão alguns sites onde você pode perguntar ou responder dúvidas MM> sobre desenvolvimento de aplicações para Android: MM> http://www.andglobe.com MM> -- MM> You received this message because you are subscribed to the Google MM> Groups "Android Developers" group. MM> To post to this group, send email to android-developers@googlegroups.com MM> To unsubscribe from this group, send email to MM> android-developers+unsubscr...@googlegroups.com MM> For more options, visit this group at MM> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Application.onCreate Method Randomly Called?
>>>>> "Jake" == Jake Colman writes: Jake> Ok. That makes sense but brings it all back full circle. Jake> It's clear that Application.onCreate is being called multiple Jake> times for my app. It also seems that my preferences are being Jake> reset as a result of that happening. But from everything that Jake> I am reading in this discussion it would seem that should not Jake> be the case. I guess I have to add some debugging code and Jake> have my user side-load it to see if I can get some insight into Jake> the problem. Jake> Incidentally, this is a fairly straighforward application with Jake> nothing fancy. It uses an AppWidget class, one Activity, a Jake> Preference Activity and a Service to do some work on behalf of Jake> the widget. So any whatever is causing my problem it's not Jake> because I am being too fancy. The key that appears to be trashed is used in Service. In the onCreate method I fetch its value from the shared preferences. The value might change as the Service does its thing. The key is committed in the Service's onDestroy method. The Service is started by my AppWidget every time the app widget needs to do some work. I do not explicitly stop the Service, relying on Android to stop it if/when needed (that is not bad practice as I understand it). In the above scenario, could the following be happening? 1) Application.onCreate is called 2) Service.onCreate is called 3) Service.onStartCommand is invoked multiple times 4) Application.onCreate is called 5) Service.onCreate is called 6) Service.onStartCommand is invoked multiple times In other words, would multiple calls to Application.onCreate cause the Service.onCreate to be called a second time without an intervening Service.onDestroy? If so, the key would not have been persisted to the shared preferences and I would have an incorrect value when processing onStartCommand. If this is the problem, is it expensive to persist a key as soon as it is changed? Or should calls to commit be bundled and done as infrequently as possible? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Application.onCreate Method Randomly Called?
>>>>> "MM" == Mark Murphy writes: MM> On Fri, Jan 18, 2013 at 10:11 AM, Jake Colman wrote: >> Am I making a fundamental mistake in how this is supposed to be done? MM> No, that all seems OK. >> You've already told me that when the application is recreated it >> gets a new context. If so, how are preferences persisted across >> recreations of my application if the "key" to those preferences >> are the context? MM> The "key" to those preferences is the package name. An easy way MM> to get the package name is by calling getPackageName() on a MM> Context. The "key" to those preferences is not the Context MM> itself. MM> In this case, the "key" is used as the basis of a filename, for MM> the XML file which contains the persisted SharedPreferences. Ok. That makes sense but brings it all back full circle. It's clear that Application.onCreate is being called multiple times for my app. It also seems that my preferences are being reset as a result of that happening. But from everything that I am reading in this discussion it would seem that should not be the case. I guess I have to add some debugging code and have my user side-load it to see if I can get some insight into the problem. Incidentally, this is a fairly straighforward application with nothing fancy. It uses an AppWidget class, one Activity, a Preference Activity and a Service to do some work on behalf of the widget. So any whatever is causing my problem it's not because I am being too fancy. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Application.onCreate Method Randomly Called?
>>>>> "MM" == Mark Murphy writes: MM> On Fri, Jan 18, 2013 at 8:58 AM, Jake Colman wrote: >> If that is not guaranteed then should I not be using context-based >> preferences to persist my data? MM> I have no idea what you consider "context-based preferences" to MM> be. If you mean static data members, they should be used as a MM> cache for persistent data or for transient purposes only. >> Is there something other than >> PreferenceManager.getDefaultSharedPreference to do this? MM> SharedPreferences are persistent, assuming that you use commit() or apply(). Please correct me if/when I use incorrect terms. I am using getDefaultSharedPreferences to access my preference keys from my Preference Screens and to get/set certain keys state data. I am committing these preferences as per standard practice. The call to getDefaultSharedPreferences takes a context. Depending on where I am making the call, the context that I am passing is either: 1) A 'this' pointer from a Preference Activity 2) A 'this' pointer from a Service 3) The 'context' parameter passed into the onReceive method of my AppWidgetProvider subclass. Am I making a fundamental mistake in how this is supposed to be done? You've already told me that when the application is recreated it gets a new context. If so, how are preferences persisted across recreations of my application if the "key" to those preferences are the context? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Permissions Security Exception
My app crashed with the following stack trace: java.lang.RuntimeException: Unable to start receiver com.jnc.zmanminder.ZMAppWidget: java.lang.SecurityException: Provider network requires ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permission I request these permissions in the Manifest. When the user installs my app doesn't that mean it is granted those permissions? If so, how/why would this crash be triggered? And if it is up to me to protect against it, where do I do that in the app? Is there a way to check up-front that I have been granted all the necessary permissions? Somehow it does not seem like I should have to deal with this. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Application.onCreate Method Randomly Called?
Interesting. I have seen ACRA crashes in my app but didn't know what to do about them. Now at least I have an explanation. But this doesn't explain why my app is behaving as if its preferences have been reset. We've established that onCreate is being called multiple times. We've also established that this is not necessarily a bad thing (although it's bad if the app has not been killed in the interim). Am I misunderstanding how to use preferences? When an app gets created it is given a context. When an app get *re*created via a second kills to onCreate (following a kill) does it get the same context? If that is not guaranteed then should I not be using context-based preferences to persist my data? Is there something other than PreferenceManager.getDefaultSharedPreference to do this? For what it's worth, I am using these shared preferences to store values from my Preferences screen AND so store certain state information for the application. ...Jake >>>>> "ZV" == Zsolt Vasvari writes: ZV> This happens to my app very infrequently also. I also use ACRA ZV> and ACRA crashes because it detects that its init() method was ZV> called twice (from Application.onCreate()) ZV> The only way ACRA init knows that it was called twice is if it ZV> wasn't killed between invocations. So this is almost certainly ZV> an Android/vendor bug where it calls onCreate() multiple times ZV> under some special conditions without killing the app in between ZV> the calls. ZV> On Friday, January 18, 2013 11:29:37 AM UTC+8, Jake Colman wrote: >> >> >>>>> "T" == TreKing > writes: >> T> On Thu, Jan 17, 2013 at 4:14 PM, Jake Colman T> > >> wrote: >> >> >> When the application is recreated I assume that it loses the >> >> previous incarnations shared preferences and, therefore, the >> >> service doesn't know that it already triggered. Hence, the false >> >> trigger when the application is recreated. >> >> >> T> SharedPreferences are persisted if you commit them so any prefs T> you set in one call to Application.onCreate() should be available T> in the next call and throughout the rest of the app. >> >> I am using PreferenceManager.getDefaultSharedPreference. I am >> committing my preferences when my Service (not the widget receiver but >> the Service that is started by the widget receiver) is destroyed and I >> read the preferences when the Service is created. One of the saved >> pieces of data stores whether the notification had already been >> triggered. Since the getDefaultSharedPreference method takes a context, >> is it possible that when the Application is recreated there is a new >> context so my saved preferences are lost? That would explain why the >> notification is re-triggered when the Application is created a second >> time. >> >> -- >> Jake Colman -- Android Tinkerer >> >> ZV> -- ZV> You received this message because you are subscribed to the Google ZV> Groups "Android Developers" group. ZV> To post to this group, send email to android-developers@googlegroups.com ZV> To unsubscribe from this group, send email to ZV> android-developers+unsubscr...@googlegroups.com ZV> For more options, visit this group at ZV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Application.onCreate Method Randomly Called?
>>>>> "T" == TreKing writes: T> On Thu, Jan 17, 2013 at 4:14 PM, Jake Colman wrote: >> When the application is recreated I assume that it loses the >> previous incarnations shared preferences and, therefore, the >> service doesn't know that it already triggered. Hence, the false >> trigger when the application is recreated. >> T> SharedPreferences are persisted if you commit them so any prefs T> you set in one call to Application.onCreate() should be available T> in the next call and throughout the rest of the app. I am using PreferenceManager.getDefaultSharedPreference. I am committing my preferences when my Service (not the widget receiver but the Service that is started by the widget receiver) is destroyed and I read the preferences when the Service is created. One of the saved pieces of data stores whether the notification had already been triggered. Since the getDefaultSharedPreference method takes a context, is it possible that when the Application is recreated there is a new context so my saved preferences are lost? That would explain why the notification is re-triggered when the Application is created a second time. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Application.onCreate Method Randomly Called?
>>>>> "T" == TreKing writes: T> On Thu, Jan 17, 2013 at 2:40 PM, Jake Colman T> wrote: >> If the application or widget is installed and that condition >> already exists at the time of installation, the notification is >> triggered. >> T> That doesn't make sense. You can't do anything when your T> *application* is first installed. First, please forgive (and correct) any incorrect usage of Android terms. In my Application class all I do is override onCreate so that I can initialize ACRA. Any "work" is being done by the widget's broadcast receiver and by an associated service class. When the application is created, it has no shared preferences with pre-existing values. So when the associated service is started it assumes that it has to trigger a notification. It knows if a notification has been triggered already so it doesn't do it again. When the application is recreated I assume that it loses the previous incarnations shared preferences and, therefore, the service doesn't know that it already triggered. Hence, the false trigger when the application is recreated. >> Why would Application.onCreate be invoked by Android after the >> application and widget were already installed and without the user >> doing anything? >> T> That would indicate your process was killed and restarted. If the T> widget was the only thing you have running, then either it or T> perhaps the home screen it was running on were killed. Not likely, T> but possible. I don't see any reason why I should have been killed. I checked with my user and they are not using a task killer. T> Why do this check in onCreate? Why not do it strictly when the T> widget is installed? Which check? Did my earlier paragraph explain what I think is happening? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Application.onCreate Method Randomly Called?
Mark, Yes, I meant an "app widget" and, yes, the app widget is being updated via android:updatePeriodMillis and the AlarmManager. The onCreate method is NOT being called following an APPWIDGET_UPDATE since I see those happening elsewhere in my debug log. The AlarmManager is managing several alarms, one of which is every 60 seconds (we've discussed this in a different thread and I will reengineer this in my next release). Since the alarm is triggering so often, it sounds unlikely that the widget was swapped out of memory since it was quiescent and then recreated on account of the alarm having triggered. Having said that, the timestamps for both events (onCreate and the alarm) are identical. ...Jake >>>>> "MM" == Mark Murphy writes: MM> I assume "widget" means "app widget". MM> In that case, is your app widget being updated, via MM> android:updatePeriodMillis or AlarmManager? MM> if the answer is "yes", then your process is being terminated in MM> between updates, then recreated on the next update, triggering a new MM> Application object and onCreate(). This is perfectly normal and MM> generally beneficial to the user. MM> On Thu, Jan 17, 2013 at 3:40 PM, Jake Colman wrote: >> >> My application extends the Application class so that I can initialize >> ACRA in the onCreateMethod. My application consists primarily of a >> widget that monitors something and sends a notification when a condition >> exists. If the application or widget is installed and that condition >> already exists at the time of installation, the notification is >> triggered. >> >> I've started getting reports that the notification will trigger at >> random even after it has already triggered correctly. I had the user >> send me my Debug Log with an email telling me when the notification was >> triggered. Based on the timestamps the notification was triggered >> because Application.onCreate was invoked. Why would >> Application.onCreate be invoked by Android after the application and >> widget were already installed and without the user doing anything? >> >> -- >> Jake Colman -- Android Tinkerer >> >> -- >> 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 MM> -- MM> Mark Murphy (a Commons Guy) MM> http://commonsware.com | http://github.com/commonsguy MM> http://commonsware.com/blog | http://twitter.com/commonsguy MM> _The Busy Coder's Guide to Android Development_ Version 4.5 Available! MM> -- MM> You received this message because you are subscribed to the Google MM> Groups "Android Developers" group. MM> To post to this group, send email to android-developers@googlegroups.com MM> To unsubscribe from this group, send email to MM> android-developers+unsubscr...@googlegroups.com MM> For more options, visit this group at MM> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Application.onCreate Method Randomly Called?
My application extends the Application class so that I can initialize ACRA in the onCreateMethod. My application consists primarily of a widget that monitors something and sends a notification when a condition exists. If the application or widget is installed and that condition already exists at the time of installation, the notification is triggered. I've started getting reports that the notification will trigger at random even after it has already triggered correctly. I had the user send me my Debug Log with an email telling me when the notification was triggered. Based on the timestamps the notification was triggered because Application.onCreate was invoked. Why would Application.onCreate be invoked by Android after the application and widget were already installed and without the user doing anything? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: location updates using network provider
>>>>> "MM" == Mark Murphy writes: MM> On Thu, Jan 10, 2013 at 8:54 AM, Jake Colman wrote: >> That's an interesting comment. I am using an alarm to wake myself >> every 60 seconds in order to check something. Are you saying this >> is not good practice? MM> For me, 60 seconds is about the threshold where I start to wonder MM> whether you are doing more harm than good with MM> AlarmManager. However, that's just a gut feel for me -- I have MM> not tried running any tests to confirm whether constantly MM> starting and stopping things will use more power than leaving MM> them run all the time. >> To make this a more practical question: I need to do something 30 >> minutes before an astronomical event. MM> Hopefully the "astronomical event" doesn't involve an impact MM> crater on Earth. :-) >> I use the alarm manager to send an intent to a service which >> checks for the time of that event (depends upon location and the >> device might have moved) and to see if we are within 30 minutes of >> the event. If so, it does something. MM> I would suggest that you give the user configuration ability MM> here. The power drain you are incurring may not be worth it to MM> all users of your app. >> Are you saying that the alarm manager is not the correct way to do >> this since I should not trigger alarms every 60 seconds? MM> Triggering an event every 60 seconds indefinitely isn't MM> great. Doing so when it is not needed is bad. Not allowing the MM> user to control this behavior would also be bad. Checking MM> location every 60 seconds may get you slapped with a trout, MM> particularly if the user cannot control this behavior. And so on. The location update is configurable by the user with a minimum update granularity of 1 hour. So the location can never change more often than every hour. I knew enough about battery consumption to not make the mistake of updating my location too often! It never occurred to me not to check the time every minute to see if it's now time to do my thing since I didn't think that would have a real impact on the battery. Hmm. Once I establish a location and I know the time of sunset, for example, I can set an alarm for 30 minutes prior to that time and be done with it. When I get a location update I can cancel that alarm and set a new one for the new time. That would certainly be easier on the system resources. How does a typical clock widget update itself to display a new time as the minutes go by? Does it do nothing unless the user turns on the screen (when the screen is off you don't need to know what time is) at which time it triggers an event and updates itself? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: location updates using network provider
>>>>> "KM" == Kristopher Micinski writes: KM> FYI 90 seconds would not really be a good fit for an KM> AlarmManager, it's not meant to be used with that kind of KM> granularity. That's an interesting comment. I am using an alarm to wake myself every 60 seconds in order to check something. Are you saying this is not good practice? To make this a more practical question: I need to do something 30 minutes before an astronomical event. I use the alarm manager to send an intent to a service which checks for the time of that event (depends upon location and the device might have moved) and to see if we are within 30 minutes of the event. If so, it does something. Are you saying that the alarm manager is not the correct way to do this since I should not trigger alarms every 60 seconds? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Implementing Simple Help Page
>>>>> "T" == TreKing writes: T> On Mon, Jan 7, 2013 at 9:29 AM, Jake Colman wrote: >> Should I create an Internet-based web page and use an activity >> with a WebView to display it? >> T> It's really up to you and depends on your app, but this is what I T> do. I have a lot of help pages (one per screen and / or feature) T> and I find it easier to update, manage, and maintain online rather T> than locally. >> If so, any recommendations for where to host a simple web page >> like this for free? >> T> There are tons of free hosts you could use. I use Google Sites. I'm leaning towards this approach. What's the URL for your help page? Maybe I can use your site as a template for my own. Or at least as a basis to get started. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Setting Widget B/G Color of the B/G Resource
I do RemoteView.setInt to call methods on the layout id. Is there a way, using a similar technique, to get access to the drawable and mutate it? In other words, change the background color of the current background resource such that the widget uses that modified resource? I'm sure that the downside of using a "hidden" API is that it can be removed in a future release and break the app. Do developers commonly accept that risk? >>>>> "KV" == Kostya Vasilyev writes: KV> https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/RemoteViews.java KV> #setDrawableParameters KV> NB: marked with a @hide. KV> -- K KV> 2013/1/1 Jake Colman >> >> I don't think it helps to get access to the drawable resource and use >> setColorFilter to set its background color since I don't see a way to >> set the modified drawable resource as the background resource for the >> view. >> >> Am I missing something obvious? I did google before posting but that >> doesn't mean I didn't miss it. >> >> >>>>> "Jake" == Jake Colman writes: >> Jake> I have written code to select at runtime whether my widget Jake> should use a background PNG image or just select a background Jake> color in place of the image. This code works fine but is not Jake> esthetically pleasing. The problem is that when I set just the Jake> background color in lieu of the image the entire grid space Jake> occupied by the widget is colored and it just looks bad. >> Jake> My next idea was to specify a different background that Jake> specifies a resource instead of the PNG image. This Jake> code works fine too. At runtime I select one of two values for Jake> setBackgroundResource and I can see either the PNG image or the Jake> shaped colored background. This shaped colored background has Jake> margins and rounded corners so it looks better than just Jake> coloring the background. >> Jake> Here is my question: Is there a way to specify the color of the Jake> shaped background at runtime? I can call RemoteView.setInt Jake> with setBackgroundResource to set the shaped background but how Jake> can I set the resource's background color? >> Jake> -- Jake> Jake Colman -- Android Tinkerer >> Jake> -- Jake> You received this message because you are subscribed to the Google Jake> Groups "Android Developers" group. Jake> To post to this group, send email to >> android-developers@googlegroups.com Jake> To unsubscribe from this group, send email to Jake> android-developers+unsubscr...@googlegroups.com Jake> For more options, visit this group at Jake> http://groups.google.com/group/android-developers?hl=en >> >> -- >> Jake Colman -- Android Tinkerer >> >> -- >> 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 >> KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@googlegroups.com KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Implementing Simple Help Page
I'd like to implement a simple Help page for my widget so that my users know all the tappable areas of the widget and what will happen when they tap. What is the best way to do this? Should I create an Internet-based web page and use an activity with a WebView to display it? If so, any recommendations for where to host a simple web page like this for free? All I need to is a Help Page; I'm not looking to create a web presence for myself or my app (at least not now). Should I create an HTML page that is included as an asset in my APK and display it myself? That certainly has drawbacks because it means that I cannot update the Help Page without release a new version of the app. On the other hand, it means I don't need to find a place to host the page. If I do go this route, can a WebView be used to view an HTML page that is resident on the phone? Any recommendations or suggestions? TIA! -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Demo Code For Clock with Auto-Location?
Homescreen widget. I want to see what approach a typical clock widget uses for auto-updating the location and for managing system resources. I have developed a widget that does some similar things and I want compare the approach that I used with how someone else did it. >>>>> "b" == bob writes: b> In Android, *widget* has two meanings. b> Are you talking about a home-screen widget? Or a subclass of View? b> On Thursday, January 3, 2013 10:26:02 AM UTC-6, Jake Colman wrote: >> >> >> Does anyone know where I can find demo code for a clock widget that >> shows the current location? I have found demo code for a clock but not >> demo code for one that updates its location. >> >> TIA! >> >> -- >> Jake Colman -- Android Tinkerer >> >> b> -- b> You received this message because you are subscribed to the Google b> Groups "Android Developers" group. b> To post to this group, send email to android-developers@googlegroups.com b> To unsubscribe from this group, send email to b> android-developers+unsubscr...@googlegroups.com b> For more options, visit this group at b> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Demo Code For Clock with Auto-Location?
Terrific! No email yet but I can wait. >>>>> "JM" == Josphat Muchiri writes: JM> Ok i can send u JM> On Jan 3, 2013 7:29 PM, "Jake Colman" wrote: >> >> Does anyone know where I can find demo code for a clock widget that >> shows the current location? I have found demo code for a clock but not >> demo code for one that updates its location. >> >> TIA! >> >> -- >> Jake Colman -- Android Tinkerer >> >> -- >> 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 >> JM> -- JM> You received this message because you are subscribed to the Google JM> Groups "Android Developers" group. JM> To post to this group, send email to android-developers@googlegroups.com JM> To unsubscribe from this group, send email to JM> android-developers+unsubscr...@googlegroups.com JM> For more options, visit this group at JM> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Demo Code For Clock with Auto-Location?
Does anyone know where I can find demo code for a clock widget that shows the current location? I have found demo code for a clock but not demo code for one that updates its location. TIA! -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Setting Widget B/G Color of the B/G Resource
I don't think it helps to get access to the drawable resource and use setColorFilter to set its background color since I don't see a way to set the modified drawable resource as the background resource for the view. Am I missing something obvious? I did google before posting but that doesn't mean I didn't miss it. >>>>> "Jake" == Jake Colman writes: Jake> I have written code to select at runtime whether my widget Jake> should use a background PNG image or just select a background Jake> color in place of the image. This code works fine but is not Jake> esthetically pleasing. The problem is that when I set just the Jake> background color in lieu of the image the entire grid space Jake> occupied by the widget is colored and it just looks bad. Jake> My next idea was to specify a different background that Jake> specifies a resource instead of the PNG image. This Jake> code works fine too. At runtime I select one of two values for Jake> setBackgroundResource and I can see either the PNG image or the Jake> shaped colored background. This shaped colored background has Jake> margins and rounded corners so it looks better than just Jake> coloring the background. Jake> Here is my question: Is there a way to specify the color of the Jake> shaped background at runtime? I can call RemoteView.setInt Jake> with setBackgroundResource to set the shaped background but how Jake> can I set the resource's background color? Jake> -- Jake> Jake Colman -- Android Tinkerer Jake> -- Jake> You received this message because you are subscribed to the Google Jake> Groups "Android Developers" group. Jake> To post to this group, send email to android-developers@googlegroups.com Jake> To unsubscribe from this group, send email to Jake> android-developers+unsubscr...@googlegroups.com Jake> For more options, visit this group at Jake> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Setting Widget B/G Color of the B/G Resource
I have written code to select at runtime whether my widget should use a background PNG image or just select a background color in place of the image. This code works fine but is not esthetically pleasing. The problem is that when I set just the background color in lieu of the image the entire grid space occupied by the widget is colored and it just looks bad. My next idea was to specify a different background that specifies a resource instead of the PNG image. This code works fine too. At runtime I select one of two values for setBackgroundResource and I can see either the PNG image or the shaped colored background. This shaped colored background has margins and rounded corners so it looks better than just coloring the background. Here is my question: Is there a way to specify the color of the shaped background at runtime? I can call RemoteView.setInt with setBackgroundResource to set the shaped background but how can I set the resource's background color? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: LocationManager.getBestProvider Returning NULL?
>>>>> "T" == TreKing writes: >> and what is the best way to handle it? >> T> Check for null? I'm already doing that! If I get NULL I hard-code a request to the NETWORK provider. Under certain circumstances I'm crashing my app since I assumed (stupidly) that when "best" returns NULL I can still access NETWORK. I guess when "best" returns NULL it really means there ain't nothing available to satisfy my request. >> And why would a device would not have a NETWORK provider? >> T> User disabled it? T> Device is in AirPlane mode? T> Device just doesn't have that radio? T> (I'm just guessing, I don't really know). That was really the core of my question. If "best" returns NULL I have to assume that I cannot determine the location - and then do something accordingly. Thanks. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] LocationManager.getBestProvider Returning NULL?
Under what circumstances will getBestProvider return NULL and what is the best way to handle it? My app uses the provider to determine the current location. If getBestProvider returns NULL I request an update from NETWORK on the assumption that there is always a NETWORK provider even if the GPS is not available. What does it mean if there is no "best"? Doesn't Android automatically relax my criteria until it finds a match? And why would a device would not have a NETWORK provider? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Location Listener Question
>>>>> "MM" == Mark Murphy writes: MM> On Thu, Dec 27, 2012 at 12:22 PM, Jake Colman wrote: >> H. The service's onHandleIntent is basically a set of >> 'if/else' clauses for the intents I am looking for with a final >> 'else' for any unrecognized intent. After that final 'else' there >> is no other code. MM> Which means your service will be destroyed a handful of MM> microseconds after that final else. Using an IntentService for MM> location tracking is a no-no. >> In my logcat I see that the code for determining the location has >> been triggered (I have debug statements showing me the available >> and best providers) but then I immediately see the service's >> onDestroy method logging that it was called. MM> That is precisely what I am telling you is supposed to happen. >> Either way, how do I make sure I stay alive long enough for my >> Listener to get an update? MM> Stop using an IntentService. Use a regular Service, one for which MM> you control the lifecycle. Sorry, I misunderstood. Initially you said that the service should not be destroyed so quickly. I didn't realize that you were distinguishing between an Intent Service and a regular service. Is it acceptable practice to have my AppWidgetProvider start a regular service to handle this kind of work? If that's the case there's not much that would likely need to change in my overall code. What about leaving everything as is but track location updates via an Intent instead of a listener? I imagine that would be abusive since an AppWidgetProvider shouldn't be handling a potentially continuous stream of intents such as could be fired from the location updates. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Location Listener Question
>>>>> "MM" == Mark Murphy writes: MM> On Thu, Dec 27, 2012 at 10:39 AM, Jake Colman wrote: >> I think I know why my listener is not always firing but I'm not >> sure what to do about it. The request for location updates is >> coming from a Service that is periodically updating a widget. >> Looking the logcat, it looks like the service gets destroyed >> before I received the update. If the service is destroyed, the >> listener object is gone too! >> >> How does one typically deal with this situation? MM> The only reason a service would be destroyed within that short a MM> period of time is if somebody stops it. For example, an MM> IntentService calls stopSelf() when onHandleIntent() ends (if MM> there is no more work queued up). H. The service's onHandleIntent is basically a set of 'if/else' clauses for the intents I am looking for with a final 'else' for any unrecognized intent. After that final 'else' there is no other code. In my logcat I see that the code for determining the location has been triggered (I have debug statements showing me the available and best providers) but then I immediately see the service's onDestroy method logging that it was called. My test phone is a vanilla HTC EVO 4G running CM7 with nothing extra installed on it. Is there anything else that can cause the service to be destroyed? In case it matters, the service is being started from the onReceive method of an AppWidgetProvider. Is it possible that the service's life cycle is shortened in that instance? Either way, how do I make sure I stay alive long enough for my Listener to get an update? MM> Handling periodic locations, triggered by alarms, is tricky, not MM> only in the location handling but in making sure the WakeLock and MM> everything is behaving as expected. I tossed together a simple MM> LocationPoller to demonstrate the sort of stuff that's required: MM> https://github.com/commonsguy/cwac-locpoll Thanks for this code. Now I need to study it! -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Location Listener Question
>>>>> "Jake" == Jake Colman writes: Jake> Yes, I know that there are a million resources out there that Jake> deal with the best way to obtain a location and I did google Jake> quite a bit before making this post. If someone can point me Jake> to something I missed, I'd appreciate it. Jake> Having said this my needs (for the purpose of this question) Jake> are quite simple: Once an hour I want to obtain my location Jake> from the Network. Jake> Here is what I did: Jake> 1) Created an alarm to trigger once an hour. Jake> 2) Invoke LocationManager.removeUpdates(). Jake> 3) Request location updates, specifying a listener. I am Jake>specifying minTime and minDistance values of 0. Jake> 4) As soon as the listener is fired, save the location and Jake>invoke LocationManager.removeUpdates(). Jake> I see a few issues with this: Jake> 1) I am shutting down the listener as soon as I get an update. Jake>But I should probably wait for a few updates in order to Jake>allow it to zero in on the location (I already have code Jake>that figures out best location from those available). Jake> 2) The listener does not seem to fire consistently. My Jake>location is not always getting updated and it looks like the Jake>listener is simply not getting called. Jake> I ran some tests where I never remove updates. With the above Jake> settings my listener is being called appx every 45 seconds. So Jake> I know that my overall code is written correctly. Jake> What is the canonical "best" way to do what I want? Should I Jake> collect updates in my Listener for, say, 2 minutes and use an Jake> alarm (set to trigger two minutes after my hourly alarm is Jake> triggered) to remove updates? Is there a better way to solve Jake> this problem? I think I know why my listener is not always firing but I'm not sure what to do about it. The request for location updates is coming from a Service that is periodically updating a widget. Looking the logcat, it looks like the service gets destroyed before I received the update. If the service is destroyed, the listener object is gone too! How does one typically deal with this situation? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Location Listener Question
Yes, I know that there are a million resources out there that deal with the best way to obtain a location and I did google quite a bit before making this post. If someone can point me to something I missed, I'd appreciate it. Having said this my needs (for the purpose of this question) are quite simple: Once an hour I want to obtain my location from the Network. Here is what I did: 1) Created an alarm to trigger once an hour. 2) Invoke LocationManager.removeUpdates(). 3) Request location updates, specifying a listener. I am specifying minTime and minDistance values of 0. 4) As soon as the listener is fired, save the location and invoke LocationManager.removeUpdates(). I see a few issues with this: 1) I am shutting down the listener as soon as I get an update. But I should probably wait for a few updates in order to allow it to zero in on the location (I already have code that figures out best location from those available). 2) The listener does not seem to fire consistently. My location is not always getting updated and it looks like the listener is simply not getting called. I ran some tests where I never remove updates. With the above settings my listener is being called appx every 45 seconds. So I know that my overall code is written correctly. What is the canonical "best" way to do what I want? Should I collect updates in my Listener for, say, 2 minutes and use an alarm (set to trigger two minutes after my hourly alarm is triggered) to remove updates? Is there a better way to solve this problem? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Geocoder Inaccurate?
>>>>> "T" == TreKing writes: T> On Thu, Aug 16, 2012 at 4:02 PM, Jake Colman wrote: >> Any idea what I need to do to make sure that my output matches my input? >> T> http://developer.android.com/reference/android/location/Address.html#setLocality%28java.lang.String%29 T> outputAddress.setLocality(inputAdress.getLocality()); I'm not sure if my prior reply went through so I'll try again. I am carrying around a Location object that was created from a previously created Address object. I am now calling Geocoder with the latitude/longitude of the Location object to create a new Address object. The new Address object is not identical to the old even though I used the exact latitude/longitude from the old one. Why would Geocoder not return an Address object with the same latitude/longitude as was passed in to its getFromLocation method? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Geocoder Inaccurate?
>>>>> "T" == TreKing writes: T> On Thu, Aug 16, 2012 at 4:02 PM, Jake Colman wrote: >> Any idea what I need to do to make sure that my output matches my input? >> T> http://developer.android.com/reference/android/location/Address.html#setLocality%28java.lang.String%29 T> outputAddress.setLocality(inputAdress.getLocality()); My bad, I was not clear enough. I am carrying around a Location object whose latitude/longitude were set from a previously obtained Address object. I feed that latitude/longitude into Geocoder to obtain a new Address object. I verified that I am feeding the exact values mentioned in my post but the new Address object doesn't get created with those values. I suspect that because the new Address object is not identical to the old, its locality is not being set the same. Am I having unreasonable expectations here? Why should Geocoder create an Address object with latitude/longitude that is different than what was passed into its getFromLocation method? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Geocoder Inaccurate?
Consider the following code snippet: Geocoder geocoder = new Geocoder( context, locale ); List address = getcoder.getFromLocation( lat, long, 1 ); My input values for latitude and longitude are: Lat: 39.9982136 Long: -75.2508229 But the latitude and longitude in my Address object are: Lat: 39.9983658 Long: -75.2509783 The reason I care is that an Address object for the original set of values has a correct value for locality while the Address object for the second set of values has null. Any idea what I need to do to make sure that my output matches my input? TIA! -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Marketplace Questions
I've just published my first paid app, a 'Pro' version of my free app. I've got two things I'm trying to understand: 1) One my users is from Israel and he says that his order cannot be processed. Google says that the credentials are incorrect. Do I need to do something special to allow international puchases? 2) Google says 4 installs but 0 active installs. But I see that I successfully processed some orders. Isn't an active install one that is being used - ergo one that was paid for? Thanks. ...Jake -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Saving a NinePatch to Temp Storage
I am trying to allow the user to specify the background color of a ninepatch that is part of my res/drawble directory. The modified ninepatch will then be set as the background image for my widget. I realize that you cannot change the contents of res/drawble so I have to write the image to temporary storage and then use setImageFromURI to point at the modified ninepatch. I cannot figure out, however, how to save the image. I have the following code: Drawable bg = this.getResources().getDrawable(R.drawable.appwidget_bg); bg.mutate(); bg.setColorFilter( color, PorterDuff.Mode.MULTIPLY ); What method can I now use to write this out? There do not seem to be any methods on Drawable that will persist an image. Is there a helper class that I need to use? I did look at BitmapFactory but, unless I misunderstood, it didn't seem to be the solution. Is there a preferred location to use for this kind of temporary file? Is there a better recommended way of doing what I am trying to do? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Setting Drawable Background Color
Thanks for the help -- but now I realize that I don't know how to get the drawable! How do create a Drawable object from the drawable resource associated with my layout? I am doing this within the context of a service and using a RemoteView. If I had the modified Drawable, I believe I can use one of the 'set' methods available to me on the RemoteView to update the background image. But how do I create the Drawable? There does not seem to be a simple way to do via the resource ID. Is there a way to create a file from the png in the drawable directory? ...Jake >>>>> "ZV" == Zsolt Vasvari writes: ZV> To color a B&W image, I use setColorFilter(color, Mode.MULTIPLY)) ZV> On Jun 20, 9:42 pm, Jake Colman wrote: >> Given that I have an integer value representing a color with an >> included alpha (opacity) value, how do I set that value in a >> drawable in order to change its background? >> >> The Drawable setColorFilter() method takes a color value and a >> color filter. This method sounds promising since it accepts a >> color value but But it's not clear to me how I should be setting >> the ColorFilter value. >> >> Can anyone help? >> >> TIA! >> >> -- >> Jake Colman -- Android Tinkerer ZV> -- ZV> You received this message because you are subscribed to the Google ZV> Groups "Android Developers" group. ZV> To post to this group, send email to android-developers@googlegroups.com ZV> To unsubscribe from this group, send email to ZV> android-developers+unsubscr...@googlegroups.com ZV> For more options, visit this group at ZV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Help Fixing a 9-patch
>>>>> "NE" == Nikolay Elenkov writes: NE> On Mon, Jun 20, 2011 at 11:06 PM, Jake Colman wrote: >> >> I realize that this is not a programming question but I'm hoping >> someone here can help with a quick solution. >> >> I have a 9-patch file that I use as my widget background. I did >> not create it, I found it on the web. I am using the image as >> both a 1x1 and 2x1 background depending on the widget size. My >> problem is that the background does not stretch to fill the full >> size of the 1x1 or 2x1 cell. NE> I seems the outer part is transparent, that is why it doesn't NE> fill your full widget size. It's a trick to make widgets look NE> smaller than the standard cell size. You need to cut out the NE> transparent bits to make it work. NE> And no, no one will do your work for you. I tried a few things but could not figure our how, after removing the transparent outer part, to resize the inner part or crop the image. Instead, I did a 'zealous crop' with the transparency layer intact and that shrunk the outer section quite nicely. Thanks for helping. ...Jake -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Help Fixing a 9-patch
Kostyra, Thanks for trying to help. The problem turned out to be that the image has an alpha channel (transparency) that is simply way bigger than I'd like. After trying a number of things, I found that a 'zealous autocrop' resized the image but kept some transparency around the edges. As a 9-patch the background resizes quite nicely as needed. Thanks. ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> The file is a nine-patch, and should fill the view KV> automatically. And I'm sorry to say, it does that just fine for KV> all my widgets. KV> If you think the issue is with this particular file, you could KV> try testing with one of the nine-patches under KV> \platforms\android-X\data\res. KV> Other than that, you could try completely cleaning the project in KV> Eclipse and/or uninstalling the application with "adb uninstall" KV> just to make sure nothing is interfering with your testing. KV> -- Kostya KV> 2011/6/20 Jake Colman >> >> Kostya, >> >> The background is specified in XML exactly as you suggested. When I >> click and hold on the widget to drag it, Android's outline box is larger >> than the widget itself. If I write code to invoke setBackgroundColor() >> in lieu of setbackgroundresource() the color fills in a larger square >> than does the background resource. Doesn't all that indicate that there >> is something about the PNG file, itself, that needs to be changed to >> make it appear larger? >> >> ...Jake >> >> >>>>> "KV" == Kostya Vasilyev writes: >> KV> I just dropped the image into my project, and set it as an KV> android:background for a layout (activity, not wiget). >> KV> It worked fine. >> KV> It's a good sign that your widget is getting filled with color - KV> perhaps there is something unusual about how you set the KV> background? >> KV> I would try the simplest thing possible - set it with KV> android:background and remove any code that might touch that. >> KV> -- Kostya >> KV> 2011/6/20 Jake Colman >> >> >> >> >> Using some new preference settings in my widget, the user can >> completely >> >> replace the background image with a color. When I do that, the >> painted >> >> area is quite a bit larger than the area covered when I use the >> >> background image. I think that is the equivalent of what you asked me >> >> to check, correct? >> >> >> >> ...Jake >> >> >> >> >> >> >>>>> "KV" == Kostya Vasilyev writes: >> >> KV> It looks fine, and enlarges properly in draw9patch. Are you KV> certain the layout where it's used as the background actually KV> gets larger width and / or height? >> >> KV> Try setting android:background="#FF008040" or some such to check. >> >> KV> -- Kostya >> >> KV> 2011/6/20 Nikolay Elenkov >> >> >> KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to >> android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@googlegroups.com KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en >> >> -- >> Jake Colman -- Android Tinkerer >> >> -- >> 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 >> KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@googlegroups.com KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Help Fixing a 9-patch
Kostya, The background is specified in XML exactly as you suggested. When I click and hold on the widget to drag it, Android's outline box is larger than the widget itself. If I write code to invoke setBackgroundColor() in lieu of setbackgroundresource() the color fills in a larger square than does the background resource. Doesn't all that indicate that there is something about the PNG file, itself, that needs to be changed to make it appear larger? ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> I just dropped the image into my project, and set it as an KV> android:background for a layout (activity, not wiget). KV> It worked fine. KV> It's a good sign that your widget is getting filled with color - KV> perhaps there is something unusual about how you set the KV> background? KV> I would try the simplest thing possible - set it with KV> android:background and remove any code that might touch that. KV> -- Kostya KV> 2011/6/20 Jake Colman >> >> Using some new preference settings in my widget, the user can completely >> replace the background image with a color. When I do that, the painted >> area is quite a bit larger than the area covered when I use the >> background image. I think that is the equivalent of what you asked me >> to check, correct? >> >> ...Jake >> >> >> >>>>> "KV" == Kostya Vasilyev writes: >> KV> It looks fine, and enlarges properly in draw9patch. Are you KV> certain the layout where it's used as the background actually KV> gets larger width and / or height? >> KV> Try setting android:background="#FF008040" or some such to check. >> KV> -- Kostya >> KV> 2011/6/20 Nikolay Elenkov >> KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@googlegroups.com KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Help Fixing a 9-patch
Using some new preference settings in my widget, the user can completely replace the background image with a color. When I do that, the painted area is quite a bit larger than the area covered when I use the background image. I think that is the equivalent of what you asked me to check, correct? ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> It looks fine, and enlarges properly in draw9patch. Are you KV> certain the layout where it's used as the background actually KV> gets larger width and / or height? KV> Try setting android:background="#FF008040" or some such to check. KV> -- Kostya KV> 2011/6/20 Nikolay Elenkov >> On Mon, Jun 20, 2011 at 11:06 PM, Jake Colman wrote: >> > >> > I realize that this is not a programming question but I'm hoping someone >> > here can help with a quick solution. >> > >> > I have a 9-patch file that I use as my widget background. I did not >> > create it, I found it on the web. I am using the image as both a 1x1 >> > and 2x1 background depending on the widget size. My problem is that the >> > background does not stretch to fill the full size of the 1x1 or 2x1 >> > cell. >> >> I seems the outer part is transparent, that is why it doesn't fill >> your full widget size. It's a trick to make widgets look smaller >> than the standard cell size. You need to cut out the transparent >> bits to make it work. >> >> And no, no one will do your work for you. >> >> -- >> 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 >> KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@googlegroups.com KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Help Fixing a 9-patch
I realize that this is not a programming question but I'm hoping someone here can help with a quick solution. I have a 9-patch file that I use as my widget background. I did not create it, I found it on the web. I am using the image as both a 1x1 and 2x1 background depending on the widget size. My problem is that the background does not stretch to fill the full size of the 1x1 or 2x1 cell. I tried using Gimp to edit the image so that it will stretch accordingly but cannot figure it out. Perhaps there are margins that need to be changed or spacing - I just don't know. I am quite sure that if I spend enough time I can learn enough about image editing to figure this out. But I suspect that to someone who already knows what they are doing this will be a trivial exercise. I realize that this is an imposition but can someone here edit the attached image so that it fills the cell in which it is being drawn and then email it back to me? I'd appreciate any help I can get. And I apologize for any imposition. Thanks. -- Jake Colman -- Android Tinkerer -- 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<>
[android-developers] Setting Drawable Background Color
Given that I have an integer value representing a color with an included alpha (opacity) value, how do I set that value in a drawable in order to change its background? The Drawable setColorFilter() method takes a color value and a color filter. This method sounds promising since it accepts a color value but But it's not clear to me how I should be setting the ColorFilter value. Can anyone help? TIA! -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Unsetting the Widget Background
I have a widget where the background is specified in the layout as a PNG image. I have just implemented code, using the RemoteView.setInt() method, to allow the user to specified a background color value to be used in lieu of my widget background image. Two questions: 1) How can I undo this background color value and revert to my background image? This way the user can fiddle with the colors but still get back to my original background. 2) How can I keep my background image but allow the user specify a new color for the image instead of a new color for the widget in place of the image? This would be preferable to replacing my image entirely and just coloring the background. Thanks. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Implementing Auto-Update of an Application
William, I'm sorry if I came across as an idiot. But what I meant was where do I found documentation of the unofficial Market API? Do I have peruse source code? Have you protected yourself somehow against the possibility that the API will not be available if/when a user updates his phone to a newer version of the OS? ...Jake >>>>> "WF" == William Ferguson writes: WF> Um, I'm not sure I can break it down any simpler. But I'll try. WF> 1) On start up of your app use the unofficial Market API to find out WF> the latest version of your app that has been published in the WF> Market. WF> 2) Compare that to the version that is running. WF> 3) If the Market version is newer present the user with a dialog WF> asking if they want to update. WF> 4) If they don take them to your app in the Market. WF> On Jun 16, 12:53 am, Jake Colman wrote: >> >>>>> "WF" == William Ferguson writes: >> >> WF> Alternatively, on start up use the (unofficial) Market API to >> WF> check if there is a newer version of your app available and if >> WF> there is present the user with a dialog offering to take them to >> WF> the Market to update. >> >> Can you provide some more details on this suggestion? >> >> Thanks. >> >> -- >> Jake Colman -- Android Tinkerer WF> -- WF> You received this message because you are subscribed to the Google WF> Groups "Android Developers" group. WF> To post to this group, send email to android-developers@googlegroups.com WF> To unsubscribe from this group, send email to WF> android-developers+unsubscr...@googlegroups.com WF> For more options, visit this group at WF> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Implementing Auto-Update of an Application
>>>>> "WF" == William Ferguson writes: WF> Alternatively, on start up use the (unofficial) Market API to WF> check if there is a newer version of your app available and if WF> there is present the user with a dialog offering to take them to WF> the Market to update. Can you provide some more details on this suggestion? Thanks. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Implementing Auto-Update of an Application
>>>>> "NE" == Nikolay Elenkov writes: NE> On Wed, Jun 15, 2011 at 10:51 PM, Chris wrote: >> I thought Market can also update an app automatically when a new >> version is pushed out, or am I living in 2009 still? >> NE> The user has to opt in for this, and most people don't bother. NE> Update notifications from Market are not too reliable either. NE> As for the original question, just put a text file with the NE> newest version at some publicly accessible URL. You can use NE> Dropbox or Google code, or S3, no need to run your own server. Can you expand on this? How would I use google code to do this? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Implementing Auto-Update of an Application
Yes, I know that. But not every user checks for updates or bothers to do it when one is available. If my app can inform the user directly that there is a newer version available, the user is more likely to actually do the update. >>>>> "a" == appel writes: a> Market will automatically notify the user when there is a new a> version available for any installed app. a> -- a> You received this message because you are subscribed to the Google a> Groups "Android Developers" group. a> To post to this group, send email to android-developers@googlegroups.com a> To unsubscribe from this group, send email to a> android-developers+unsubscr...@googlegroups.com a> For more options, visit this group at a> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Implementing Auto-Update of an Application
Can anyone suggest a technique for allowing an app to provide the option of checking and installing updates without implementing a back-end server? I am currently a small developer and I am loathe to go to the trouble of creating a server (at this time) just for the purposes of allowing the app to know there is a newer version. Has anyone else addressed this issue? Maybe there is a way to check the market for an updated link? Thanks. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Android LifeCycle and Singleton Instances
Mark, et al, Thanks for all the replies. My use of the singleton pattern was correct as was confirmed by these posts. I did find my issues - one of which _was_ due to not handling lifecyle correctly - and now all is well. ...Jake >>>>> "MM" == Mark Murphy writes: MM> Note that this will only work single-threaded. Add the MM> synchronized keyword to the method and make the static data MM> member volatile to make it safe for multi-threaded access. MM> (a problem I ran into with WakefulIntentService, which is why MM> this issue is fresh in my mind...) MM> On Wed, Jun 1, 2011 at 10:34 PM, Streets Of Boston MM> wrote: >> The code below will work fine for a singleton: >> ... >> private static MyObject myObject = null; >> public static MyObject getMyObject() { >> if (myObject == null { >> myObject = new MyObject(); >> } >> return myObject; >> } >> >> Note that variable won't be 'reset' to null. There is nothing to reset when >> your process is killed. It is gone, nohting left. >> >> When a new process is started, i.e. the process that will run your app >> again, then the static fields are all properly initialized (in this case, >> 'myObject' to the value 'null'). >> >> >> -- >> 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 MM> -- MM> Mark Murphy (a Commons Guy) MM> http://commonsware.com | http://github.com/commonsguy MM> http://commonsware.com/blog | http://twitter.com/commonsguy MM> Android 3.0 Programming Books: http://commonsware.com/books MM> -- MM> You received this message because you are subscribed to the Google MM> Groups "Android Developers" group. MM> To post to this group, send email to android-developers@googlegroups.com MM> To unsubscribe from this group, send email to MM> android-developers+unsubscr...@googlegroups.com MM> For more options, visit this group at MM> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Android LifeCycle and Singleton Instances
So as long as I always call my getInstance() class I can be certain that I will get a pointer to the already constructed object or that the static instance variable had been reset to NULL triggering new construction? >>>>> "DH" == Dianne Hackborn writes: DH> If your process is killed, the next time you run a fresh process DH> must be created and re-initialized. There is no way to get a DH> "stale" pointer across this. If the pointer was stale, you'd DH> probably have a native crash because it would be completely DH> unrelated to the current process you are running. DH> You can verify the behavior yourself just by using adb shell to DH> kill your process. DH> On Wed, Jun 1, 2011 at 5:39 PM, Jake Colman wrote: >> >> I was pretty sure that I understood the Android lifecycle and how >> applications/processes might be start/stopped/removed and how that >> effects whether variables remain initialized. I am, however, seeing >> some funky behavior in my app such that I am afraid I have missed >> something. >> >> I use a singleton pattern for some of my objects. That is, the >> constructor is private and you call a static getInstance() method to >> construct the object. The static instance variable is, of course, >> initialized to NULL which is the trigger for getInstance to know whether >> the object needs to be constructed. >> >> I have learned that any code that calls getInstance() cannot assume that >> the object it has constructed continues to live in memory since my >> application might have been killed by Android. So throughout my code I >> always call getInstance() to ensure that I have a valid object. Am I >> correct in assuming that had I been killed that getInstance() will >> create a new object? In other words, will my static instance variable >> have been reset to NULL or might my factory method give me back a stale >> pointer? >> >> ...Jake >> >> >> -- >> Jake Colman -- Android Tinkerer >> >> -- >> 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 >> DH> -- DH> Dianne Hackborn DH> Android framework engineer DH> hack...@android.com DH> Note: please don't send private questions to me, as I don't have time to DH> provide private support, and so won't reply to such e-mails. All such DH> questions should be posted on public forums, where I and others can see and DH> answer them. DH> -- DH> You received this message because you are subscribed to the Google DH> Groups "Android Developers" group. DH> To post to this group, send email to android-developers@googlegroups.com DH> To unsubscribe from this group, send email to DH> android-developers+unsubscr...@googlegroups.com DH> For more options, visit this group at DH> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Android LifeCycle and Singleton Instances
I was pretty sure that I understood the Android lifecycle and how applications/processes might be start/stopped/removed and how that effects whether variables remain initialized. I am, however, seeing some funky behavior in my app such that I am afraid I have missed something. I use a singleton pattern for some of my objects. That is, the constructor is private and you call a static getInstance() method to construct the object. The static instance variable is, of course, initialized to NULL which is the trigger for getInstance to know whether the object needs to be constructed. I have learned that any code that calls getInstance() cannot assume that the object it has constructed continues to live in memory since my application might have been killed by Android. So throughout my code I always call getInstance() to ensure that I have a valid object. Am I correct in assuming that had I been killed that getInstance() will create a new object? In other words, will my static instance variable have been reset to NULL or might my factory method give me back a stale pointer? ...Jake -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widget-specific Preferences
Actually, the reason we went down this path in the first place was because if I did not reset the keys during the inflation process the Preference Screen did not reflect the current values. I can still use a second pass, however, inside of onCreate() but after inflation to reset the dependent keys. That should probably work. >>>>> "Jake" == Jake Colman writes: Jake> Kostya, Jake> You did not waste my time at all! First of all, this was a Jake> great learning opportunity. Second of all, the suggestion was Jake> great - this should have worked! Maybe I need to do a second Jake> pass, somehow, to reset the dependent keys. But if I need a Jake> second pass, maybe I just do it all at that time. Jake> ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> Jake, KV> I just tried it with a simple test, and yes, I get the same KV> exception. KV> The reason is that setDependency() tries to register the KV> dependency right away, and doesn't find the depndency because the KV> process of loading preferences from XML hasn't completed yet KV> (which it does not check). It *might* be possible to work around KV> it with more overrides here and there, but... instead... KV> I admit that the idea only seemed good, and then was crushed to KV> pieces by the reality of how things work. KV> My apologies for having wasted your time. KV> -- Kostya KV> 2011/5/27 Jake Colman >>> >>> Kostya/String, >>> >>> Is nothing ever easy? So close, yet so far... :-) >>> >>> Some of my preferences have dependent keys. Since the keys are being >>> renamed to be widget-specific I, of course, have to rename the >>> dependent >>> keys accordingly as well. >>> >>> Pref2 is dependent on Pref1. Pref1 comes through my overridden >>> onPrepareAddPreference and I call setKey to rename its key. Pref2 >>> comes >>> through onPrepareAddPreference and I reset its key as usual and I also >>> reset its dependent key to have the correct Pref1 key name. This >>> triggers a java.lang.IllegalStateException stating that Dependency not >>> found for preference. >>> >>> Since Pref1 has already been reset I would expect that by the time >>> Pref2 >>> comes in Pref1 is already out there. Also, I did not think that >>> ordering would matter anyway as long as all the keys make sense at the >>> of the inflation. >>> >>> Any ideas? >>> >>> Incidentally, I tried both onPrepareAddPreference and addPreference >>> just >>> in case one worked differently than the other. And, yes, I called up >>> to >>> super at the end of my overridden method. >>> >>> ...Jake >>> >>> >>> >>>>> "KV" == Kostya Vasilyev writes: >>> KV> Yes, a cast is what I'm suggesting. From the design point of KV> view, you'll end up with two classes that are meant to be used KV> together. >>> KV> You could even do an instanceof check before the cast, and throw KV> an exception with a nice descriptive message if the check returns KV> false :) >>> KV> -- KV> Kostya Vasilyev KV> 27.05.2011 1:56 пользователь "Jake Colman" KV> KV> написал: >>> >> >>> >> >>> >> All the magic happens from addPreferencesFromResource which inflates >>> my >>> >> preferences XML and instantiates the Preference objects. With >>> >> everything we've discussed until now, I know what/how to subclass so >>> >> that I can hook into things at the correct level to reset my >>> >> key. But >>> >> if it's WidgetOptionsActivity that has the widget id (from its super >>> >> class) how does that get passed into addPreferencesFromResource? >>> >> >>> >> Unless you are suggesting that I can call a method via the context >>> which >>> >> is, in essence, my Activity? So cast the context into the Activity >>> >> and >>> >> call the method? >>> >> >>> >> >>> >>>>>>> "KV" == Kostya Vasilyev writes: >>> >> KV> Preferences are inflated with a Context, which in this case is KV> your P
[android-developers] Re: Widget-specific Preferences
Kostya, You did not waste my time at all! First of all, this was a great learning opportunity. Second of all, the suggestion was great - this should have worked! Maybe I need to do a second pass, somehow, to reset the dependent keys. But if I need a second pass, maybe I just do it all at that time. ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> Jake, KV> I just tried it with a simple test, and yes, I get the same KV> exception. KV> The reason is that setDependency() tries to register the KV> dependency right away, and doesn't find the depndency because the KV> process of loading preferences from XML hasn't completed yet KV> (which it does not check). It *might* be possible to work around KV> it with more overrides here and there, but... instead... KV> I admit that the idea only seemed good, and then was crushed to KV> pieces by the reality of how things work. KV> My apologies for having wasted your time. KV> -- Kostya KV> 2011/5/27 Jake Colman >> >> Kostya/String, >> >> Is nothing ever easy? So close, yet so far... :-) >> >> Some of my preferences have dependent keys. Since the keys are being >> renamed to be widget-specific I, of course, have to rename the dependent >> keys accordingly as well. >> >> Pref2 is dependent on Pref1. Pref1 comes through my overridden >> onPrepareAddPreference and I call setKey to rename its key. Pref2 comes >> through onPrepareAddPreference and I reset its key as usual and I also >> reset its dependent key to have the correct Pref1 key name. This >> triggers a java.lang.IllegalStateException stating that Dependency not >> found for preference. >> >> Since Pref1 has already been reset I would expect that by the time Pref2 >> comes in Pref1 is already out there. Also, I did not think that >> ordering would matter anyway as long as all the keys make sense at the >> of the inflation. >> >> Any ideas? >> >> Incidentally, I tried both onPrepareAddPreference and addPreference just >> in case one worked differently than the other. And, yes, I called up to >> super at the end of my overridden method. >> >> ...Jake >> >> >> >>>>> "KV" == Kostya Vasilyev writes: >> KV> Yes, a cast is what I'm suggesting. From the design point of KV> view, you'll end up with two classes that are meant to be used KV> together. >> KV> You could even do an instanceof check before the cast, and throw KV> an exception with a nice descriptive message if the check returns KV> false :) >> KV> -- KV> Kostya Vasilyev KV> 27.05.2011 1:56 пользователь "Jake Colman" KV> KV> написал: >> >> >> >> >> >> All the magic happens from addPreferencesFromResource which inflates >> my >> >> preferences XML and instantiates the Preference objects. With >> >> everything we've discussed until now, I know what/how to subclass so >> >> that I can hook into things at the correct level to reset my key. But >> >> if it's WidgetOptionsActivity that has the widget id (from its super >> >> class) how does that get passed into addPreferencesFromResource? >> >> >> >> Unless you are suggesting that I can call a method via the context >> which >> >> is, in essence, my Activity? So cast the context into the Activity and >> >> call the method? >> >> >> >> >> >>>>>>> "KV" == Kostya Vasilyev writes: >> >> KV> Preferences are inflated with a Context, which in this case is KV> your PreferenceActivity subclass. >> >> KV> I'd make two classes, WidgetOptionsActivity and KV> WidgetOptionsPreferenceCategory, with the expectation that the KV> latter is always used within the former (like maps API and KV> MapActivity). >> >> KV> The widget id is passed to the activity as an intent extra, so KV> just get it from there and make available as a method / field KV> before you call addPreferencesFromResource(). >> >> KV> Then you could derive YourProjectNameWidgetOptionsActivity from KV> WidgetOptionsActivity. >> >> KV> -- Kostya >> >> KV> 2011/5/27 Jake Colman >> >> >> >> >> >> >> >> Thanks Kos
[android-developers] Re: Widget-specific Preferences
Kostya/String, Is nothing ever easy? So close, yet so far... :-) Some of my preferences have dependent keys. Since the keys are being renamed to be widget-specific I, of course, have to rename the dependent keys accordingly as well. Pref2 is dependent on Pref1. Pref1 comes through my overridden onPrepareAddPreference and I call setKey to rename its key. Pref2 comes through onPrepareAddPreference and I reset its key as usual and I also reset its dependent key to have the correct Pref1 key name. This triggers a java.lang.IllegalStateException stating that Dependency not found for preference. Since Pref1 has already been reset I would expect that by the time Pref2 comes in Pref1 is already out there. Also, I did not think that ordering would matter anyway as long as all the keys make sense at the of the inflation. Any ideas? Incidentally, I tried both onPrepareAddPreference and addPreference just in case one worked differently than the other. And, yes, I called up to super at the end of my overridden method. ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> Yes, a cast is what I'm suggesting. From the design point of KV> view, you'll end up with two classes that are meant to be used KV> together. KV> You could even do an instanceof check before the cast, and throw KV> an exception with a nice descriptive message if the check returns KV> false :) KV> -- KV> Kostya Vasilyev KV> 27.05.2011 1:56 пользователь "Jake Colman" KV>написал: >> >> >> All the magic happens from addPreferencesFromResource which inflates my >> preferences XML and instantiates the Preference objects. With >> everything we've discussed until now, I know what/how to subclass so >> that I can hook into things at the correct level to reset my key. But >> if it's WidgetOptionsActivity that has the widget id (from its super >> class) how does that get passed into addPreferencesFromResource? >> >> Unless you are suggesting that I can call a method via the context which >> is, in essence, my Activity? So cast the context into the Activity and >> call the method? >> >> >>>>>>> "KV" == Kostya Vasilyev writes: >> KV> Preferences are inflated with a Context, which in this case is KV> your PreferenceActivity subclass. >> KV> I'd make two classes, WidgetOptionsActivity and KV> WidgetOptionsPreferenceCategory, with the expectation that the KV> latter is always used within the former (like maps API and KV> MapActivity). >> KV> The widget id is passed to the activity as an intent extra, so KV> just get it from there and make available as a method / field KV> before you call addPreferencesFromResource(). >> KV> Then you could derive YourProjectNameWidgetOptionsActivity from KV> WidgetOptionsActivity. >> KV> -- Kostya >> KV> 2011/5/27 Jake Colman >> >> >> >> >> Thanks Kostya and String, these were great answers. >> >> >> >> I can see how I can create my own subclass and use them instead of my >> >> the android classes. My problem now is that it is the Preference >> >> Activity, through an intent extra, that knows the specific widget ID KV> for >> >> which it is being displayed. I don't see that the Preference or >> >> PreferenceCategory subclassses have access to the parent activity that >> >> caused them to be created. Since Android is instantiating my subclasses >> >> for me, I don't see how I have a hook to pass the subclass the crucial >> >> piece of data required to reset its key - which is the whole purpose of >> >> this exercise. >> >> >> >> It looks like onPrepareAddPreference is probable the better place to >> >> reset the key than is addPreference simply because this is more of a >> >> preparation step anyway. It's great to have multiple options! >> >> >> >> ...Jake >> >> >> >> >> >> >>>>> "KV" == Kostya Vasilyev writes: >> >> KV> Where your preference class needs to have the standard KV> constructor, just like with views: >> >> KV> public class MyPreferenceCategory extends PreferenceCategory { >> >> KV> public MyPreferenceCategory(Context context, AttributeSet attrs) >> >> { KV> super(context, attrs); KV> } >> >> K
[android-developers] Re: Widget-specific Preferences
String, Where did you find the documentation to do this? I would like to add my own XML attributes to my derived preference and would like to know how do it. I considered your's and Kostya's suggestions elsewhere in this thread and decided to implement a derived PreferenceGroup with an onPrepareAddPreference method to reset the key. As it turns out, since not all of my Preferences are widget-specific (e.g., the "Debug Enabled" preference is global) I would like to derive my own Preference type and add an XML attribute to indicate whether it is widget-specific. Expanding on this technique I can then ask the widget whether it needs to have its key modified. ...Jake >>>>> "S" == String writes: S> In your XML settings-definition file, here's what you need. Just S> use: android:key="pref_key" S> ... S> /> S> where "com.my.package" is your package name, and PrefSubclass is S> the class name of your Preference subclass. Use this instead of: S> android:key="pref_key" S> ... S> /> S> or whatever Preference class you're basing it off of. S> String S> -- S> You received this message because you are subscribed to the Google S> Groups "Android Developers" group. S> To post to this group, send email to android-developers@googlegroups.com S> To unsubscribe from this group, send email to S> android-developers+unsubscr...@googlegroups.com S> For more options, visit this group at S> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widget-specific Preferences
All the magic happens from addPreferencesFromResource which inflates my preferences XML and instantiates the Preference objects. With everything we've discussed until now, I know what/how to subclass so that I can hook into things at the correct level to reset my key. But if it's WidgetOptionsActivity that has the widget id (from its super class) how does that get passed into addPreferencesFromResource? Unless you are suggesting that I can call a method via the context which is, in essence, my Activity? So cast the context into the Activity and call the method? >>>>> "KV" == Kostya Vasilyev writes: KV> Preferences are inflated with a Context, which in this case is KV> your PreferenceActivity subclass. KV> I'd make two classes, WidgetOptionsActivity and KV> WidgetOptionsPreferenceCategory, with the expectation that the KV> latter is always used within the former (like maps API and KV> MapActivity). KV> The widget id is passed to the activity as an intent extra, so KV> just get it from there and make available as a method / field KV> before you call addPreferencesFromResource(). KV> Then you could derive YourProjectNameWidgetOptionsActivity from KV> WidgetOptionsActivity. KV> -- Kostya KV> 2011/5/27 Jake Colman >> >> Thanks Kostya and String, these were great answers. >> >> I can see how I can create my own subclass and use them instead of my >> the android classes. My problem now is that it is the Preference >> Activity, through an intent extra, that knows the specific widget ID for >> which it is being displayed. I don't see that the Preference or >> PreferenceCategory subclassses have access to the parent activity that >> caused them to be created. Since Android is instantiating my subclasses >> for me, I don't see how I have a hook to pass the subclass the crucial >> piece of data required to reset its key - which is the whole purpose of >> this exercise. >> >> It looks like onPrepareAddPreference is probable the better place to >> reset the key than is addPreference simply because this is more of a >> preparation step anyway. It's great to have multiple options! >> >> ...Jake >> >> >> >>>>> "KV" == Kostya Vasilyev writes: >> KV> Where your preference class needs to have the standard KV> constructor, just like with views: >> KV> public class MyPreferenceCategory extends PreferenceCategory { >> KV> public MyPreferenceCategory(Context context, AttributeSet attrs) >> { KV> super(context, attrs); KV> } >> KV> } >> KV> And here is another useful override: >> KV> >> http://developer.android.com/reference/android/preference/PreferenceGroup.html#onPrepareAddPreference(android.preference.Preference KV> ) >> KV> onPrepareAddPreference >> KV> -- Kostya >> KV> 2011/5/27 String >> >> >> In your XML settings-definition file, here's what you need. Just use: >> >> >> >> > >> android:key="pref_key" >> >> ... >> >> /> >> >> >> >> where "com.my.package" is your package name, and PrefSubclass is the >> class >> >> name of your Preference subclass. Use this instead of: >> >> >> >> > >> android:key="pref_key" >> >> ... >> >> /> >> >> >> >> or whatever Preference class you're basing it off of. >> >> >> >> String >> >> >> >> -- >> >> 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 >> >> >> KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to >> android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@goo
[android-developers] Re: Widget-specific Preferences
Thanks Kostya and String, these were great answers. I can see how I can create my own subclass and use them instead of my the android classes. My problem now is that it is the Preference Activity, through an intent extra, that knows the specific widget ID for which it is being displayed. I don't see that the Preference or PreferenceCategory subclassses have access to the parent activity that caused them to be created. Since Android is instantiating my subclasses for me, I don't see how I have a hook to pass the subclass the crucial piece of data required to reset its key - which is the whole purpose of this exercise. It looks like onPrepareAddPreference is probable the better place to reset the key than is addPreference simply because this is more of a preparation step anyway. It's great to have multiple options! ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> Where your preference class needs to have the standard KV> constructor, just like with views: KV> public class MyPreferenceCategory extends PreferenceCategory { KV> public MyPreferenceCategory(Context context, AttributeSet attrs) { KV> super(context, attrs); KV> } KV> } KV> And here is another useful override: KV> http://developer.android.com/reference/android/preference/PreferenceGroup.html#onPrepareAddPreference(android.preference.Preference KV> ) KV> onPrepareAddPreference KV> -- Kostya KV> 2011/5/27 String >> In your XML settings-definition file, here's what you need. Just use: >> >> > android:key="pref_key" >> ... >> /> >> >> where "com.my.package" is your package name, and PrefSubclass is the class >> name of your Preference subclass. Use this instead of: >> >> > android:key="pref_key" >> ... >> /> >> >> or whatever Preference class you're basing it off of. >> >> String >> >> -- >> 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 >> KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@googlegroups.com KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widget-specific Preferences
Kostya, Googling for "android preference subclassing" didn't quite do it. Can you point me in the right direction? What is the format of the XML entry so that it know how to find my subclass? Does the subclass have any requirements if all it will do is override addPreference? Where can I find the info on all this in the developer documentation? ...Jake >>>>> "Jake" == Jake Colman writes: Jake> Now to Google and figure out how to use my own subclass in an Jake> XML preferences file! Jake> Thanks! Jake> ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> Jake, KV> My turn to think I'm missing something. KV> I imagine you have a subclass of PreferenceActivity, with KV> onCreate calling addPreferencesFromResource(R.xml. here>). KV> In that XML file, you have your preference item definitions. KV> You can use your own {sub}classes in that XML file, just like KV> with layouts and views (e.g. for a list-of-options type KV> preference, I got sick of having to convert between integers and KV> strings at some point, which is necessary if you use KV> ListPreference, and wrote my own class that uses a list of KV> integers). KV> Now as it turns out, PreferenceScreen is "final" (what the?) so KV> you can't subclass that, but PreferenceCategory is not final, so KV> it can be subclassed and specified in the XML. KV> -- Kostya KV> 2011/5/26 Jake Colman >>> >>> Kostya, >>> >>> Maybe I'm missing something obvious here but where do I get an >>> opportunity to provide Android with my extended PreferenceGroup or >>> PreferenceScreen? I need to make sure that my addPreference method >>> called during the processing sequence initiated by >>> addPreferencesFromResource. But how would that code know to use my >>> extended PreferenceScreen so that it uses my overridden addPreference >>> method? Is there a 'set' method somewhere that allows me to specify my >>> extended class? >>> >>> ...Jake >>> >>> >>> >>>>> "KV" == Kostya Vasilyev writes: >>> KV> Preference.onSetInitialValue is triggered by KV> addPreferencesFromResource, which in turn is called from within KV> your activity's onCreate - not before. >>> KV> However, this happens before your code has a change to call KV> findPreference / setKey. >>> KV> One of the methods that gets called while this is taking place is KV> PreferenceGroup.addPreference. This could be a reasonable place KV> to reset the keys, so it happens before onSetInitialValue. The KV> actual subclasses are PreferenceScreen and PreferenceCategory. >>> KV> You can check for a specifc runtime class by using Java KV> 'instanceof' operator (but this should not be necessary with KV> overiding addPreference). >>> KV> -- Kostya >>> KV> 2011/5/26 Jake Colman >>> >>> >> >>>>> "S" == String writes: >>> >> S> On Thursday, May 26, 2011 2:44:37 AM UTC+1, Jake Colman wrote: >>> >> S> The only issue is when I launch the Preference >>> >> >> Activity from the widget it does not display the widget-specific >>> >> value >>> >> >> but displays the preference's default value. >>> >> >> S> Are you actively setting the value for each of your S> widget-specific preferences, or are you just setting the key and S> hoping they'll pick up the correct (initial) value from the S> SharedPreferences? I think you need to do the former rather than S> the latter. >>> >> S> IOW, my experience is that the initialization of the preferences S> in a PreferenceActivity happens before your onCreate() handler is S> called, so changing preferences' keys there won't affect their S> displayed values. You should just need a simple call to S> setChecked() for each boolean preference to initialize it to the S> appropriate, widget-specific value. >>> >> >>> >> String, >>> >> >>> >> What I am seeing is consistent with what you stated, namely, that by >>> the >>> >> time onCreate is called, the preferences are already initialized so >>> the >>> >> displayed values have already been set. But why does t
[android-developers] Re: Widget-specific Preferences
Kostya, Bingo! I didn't realize that you can use your own subclasses in the XML file! And I also tripped over that "convert between integers and strings" issue way back when. Thank goodness for being able to Google and fine that it was a known problem with a known workaround. Now I have to decide if it's worth subclassing PreferenceCategory or if I should just use instanceof. Since it's just PreferenceCategory that would change in my XML its probably wortwhile doing - and potentially more stable in the long-term than instanceof. Now to Google and figure out how to use my own subclass in an XML preferences file! Thanks! ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> Jake, KV> My turn to think I'm missing something. KV> I imagine you have a subclass of PreferenceActivity, with KV> onCreate calling addPreferencesFromResource(R.xml. here>). KV> In that XML file, you have your preference item definitions. KV> You can use your own {sub}classes in that XML file, just like KV> with layouts and views (e.g. for a list-of-options type KV> preference, I got sick of having to convert between integers and KV> strings at some point, which is necessary if you use KV> ListPreference, and wrote my own class that uses a list of KV> integers). KV> Now as it turns out, PreferenceScreen is "final" (what the?) so KV> you can't subclass that, but PreferenceCategory is not final, so KV> it can be subclassed and specified in the XML. KV> -- Kostya KV> 2011/5/26 Jake Colman >> >> Kostya, >> >> Maybe I'm missing something obvious here but where do I get an >> opportunity to provide Android with my extended PreferenceGroup or >> PreferenceScreen? I need to make sure that my addPreference method >> called during the processing sequence initiated by >> addPreferencesFromResource. But how would that code know to use my >> extended PreferenceScreen so that it uses my overridden addPreference >> method? Is there a 'set' method somewhere that allows me to specify my >> extended class? >> >> ...Jake >> >> >> >>>>> "KV" == Kostya Vasilyev writes: >> KV> Preference.onSetInitialValue is triggered by KV> addPreferencesFromResource, which in turn is called from within KV> your activity's onCreate - not before. >> KV> However, this happens before your code has a change to call KV> findPreference / setKey. >> KV> One of the methods that gets called while this is taking place is KV> PreferenceGroup.addPreference. This could be a reasonable place KV> to reset the keys, so it happens before onSetInitialValue. The KV> actual subclasses are PreferenceScreen and PreferenceCategory. >> KV> You can check for a specifc runtime class by using Java KV> 'instanceof' operator (but this should not be necessary with KV> overiding addPreference). >> KV> -- Kostya >> KV> 2011/5/26 Jake Colman >> >> >> >>>>> "S" == String writes: >> >> S> On Thursday, May 26, 2011 2:44:37 AM UTC+1, Jake Colman wrote: >> >> S> The only issue is when I launch the Preference >> >> >> Activity from the widget it does not display the widget-specific >> >> value >> >> >> but displays the preference's default value. >> >> >> S> Are you actively setting the value for each of your S> widget-specific preferences, or are you just setting the key and S> hoping they'll pick up the correct (initial) value from the S> SharedPreferences? I think you need to do the former rather than S> the latter. >> >> S> IOW, my experience is that the initialization of the preferences S> in a PreferenceActivity happens before your onCreate() handler is S> called, so changing preferences' keys there won't affect their S> displayed values. You should just need a simple call to S> setChecked() for each boolean preference to initialize it to the S> appropriate, widget-specific value. >> >> >> >> String, >> >> >> >> What I am seeing is consistent with what you stated, namely, that by >> the >> >> time onCreate is called, the preferences are already initialized so >> the >> >> displayed values have already been set. But why does this only effect >> >> my CheckBoxPreferences whil my
[android-developers] Re: Widget-specific Preferences
Kostya, Maybe I'm missing something obvious here but where do I get an opportunity to provide Android with my extended PreferenceGroup or PreferenceScreen? I need to make sure that my addPreference method called during the processing sequence initiated by addPreferencesFromResource. But how would that code know to use my extended PreferenceScreen so that it uses my overridden addPreference method? Is there a 'set' method somewhere that allows me to specify my extended class? ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> Preference.onSetInitialValue is triggered by KV> addPreferencesFromResource, which in turn is called from within KV> your activity's onCreate - not before. KV> However, this happens before your code has a change to call KV> findPreference / setKey. KV> One of the methods that gets called while this is taking place is KV> PreferenceGroup.addPreference. This could be a reasonable place KV> to reset the keys, so it happens before onSetInitialValue. The KV> actual subclasses are PreferenceScreen and PreferenceCategory. KV> You can check for a specifc runtime class by using Java KV> 'instanceof' operator (but this should not be necessary with KV> overiding addPreference). KV> -- Kostya KV> 2011/5/26 Jake Colman >> >>>>> "S" == String writes: >> S> On Thursday, May 26, 2011 2:44:37 AM UTC+1, Jake Colman wrote: >> S> The only issue is when I launch the Preference >> >> Activity from the widget it does not display the widget-specific >> value >> >> but displays the preference's default value. >> >> S> Are you actively setting the value for each of your S> widget-specific preferences, or are you just setting the key and S> hoping they'll pick up the correct (initial) value from the S> SharedPreferences? I think you need to do the former rather than S> the latter. >> S> IOW, my experience is that the initialization of the preferences S> in a PreferenceActivity happens before your onCreate() handler is S> called, so changing preferences' keys there won't affect their S> displayed values. You should just need a simple call to S> setChecked() for each boolean preference to initialize it to the S> appropriate, widget-specific value. >> >> String, >> >> What I am seeing is consistent with what you stated, namely, that by the >> time onCreate is called, the preferences are already initialized so the >> displayed values have already been set. But why does this only effect >> my CheckBoxPreferences whil my ListPrefeference values are being set >> correctly? >> >> When I call findPreference is there a way for me to determine the >> specific derived Preference class that I acually got? With C++ I can >> dynamic_cast the base class to find out its actual type. How does one >> do the same in Java? If so, then in the method that resets the generic >> preference key to a widget-specific key I can check whether the >> Preference is actually a checkbox and then get and set its actual value. >> >> Hm. Maybe I should just write some code to always just drill into >> the SharedPreferences and manually set the value across all types. As >> long as I can query the Preference object to get its specific type, I >> can generically explicitly set the value for all preferences. >> >> -- >> Jake Colman -- Android Tinkerer >> >> -- >> 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 >> KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@googlegroups.com KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widget-specific Preferences
>>>>> "S" == String writes: S> On Thursday, May 26, 2011 2:44:37 AM UTC+1, Jake Colman wrote: S> The only issue is when I launch the Preference >> Activity from the widget it does not display the widget-specific value >> but displays the preference's default value. >> S> Are you actively setting the value for each of your S> widget-specific preferences, or are you just setting the key and S> hoping they'll pick up the correct (initial) value from the S> SharedPreferences? I think you need to do the former rather than S> the latter. S> IOW, my experience is that the initialization of the preferences S> in a PreferenceActivity happens before your onCreate() handler is S> called, so changing preferences' keys there won't affect their S> displayed values. You should just need a simple call to S> setChecked() for each boolean preference to initialize it to the S> appropriate, widget-specific value. String, What I am seeing is consistent with what you stated, namely, that by the time onCreate is called, the preferences are already initialized so the displayed values have already been set. But why does this only effect my CheckBoxPreferences whil my ListPrefeference values are being set correctly? When I call findPreference is there a way for me to determine the specific derived Preference class that I acually got? With C++ I can dynamic_cast the base class to find out its actual type. How does one do the same in Java? If so, then in the method that resets the generic preference key to a widget-specific key I can check whether the Preference is actually a checkbox and then get and set its actual value. Hm. Maybe I should just write some code to always just drill into the SharedPreferences and manually set the value across all types. As long as I can query the Preference object to get its specific type, I can generically explicitly set the value for all preferences. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widget-specific Preferences
>>>>> "Jake" == Jake Colman writes: Jake> I am looking to implemented widget-specific preferences in my Jake> app. I have reviewed numerous blogs and posts, including Jake> Kostya's, and am familiar with the overall approach of using Jake> the widget ID as a suffix to the preference key. Jake> I currently use a Preference Activity and a preference XML file Jake> to manage my preferences. Since a Preference Activity handles Jake> edits on its own, is there still a way to use it if I need to Jake> change the key name at runtime to have a widget id? I am Jake> pretty sure I can get the widget from the intent since it is Jake> launched as a configuration activity but can I tap in and use Jake> it? I'd like to continue this old thread. I have not been able to devote enough concentrated time to this but I am finally just about there. I am now able to support widget-specific preferences and the widget's honor their widget-specific value. The problem now is that when I redisplay my Preference Activity the screen does not display the correct values for booleans. It looks to me like the Preference Activity is being instantiated with the default values from the generic keys. How can I force the screen to get its values from the widget-specific keys? To provide some background on what I have already done, in my Preference Activity onCreate() method I use findPreference() to reset each preference's generic key to have the widget-specific key value. Anywhere in my code that I need to retrieve a preference value, I construct the widget-specific key name and get the data. All this is working correctly. The only issue is when I launch the Preference Activity from the widget it does not display the widget-specific value but displays the preference's default value. Any ideas? Do I need to derive from Preference Screen so that I can get access to the protected 'get' methods that access persisted values from the SharedPreferences? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Career as an Andoid developer. Is there any point?
>>>>> "D" == DanH writes: D> You don't believe everyone else is talking religion? Look how D> people jumped on me. I think most people would just like to hear why you think this way. Clearly, since this is an Android forum, most people would probably disagree with your assessment. But that doesn't mean that we are unthinking individuals. I, for one, would simply like to understand your position. I may or may not agree with you and I may or may not choose to debate with you. And you can choose to engage in discourse or move on. But it would be interesting to hear your rationale for your position. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Career as an Andoid developer. Is there any point?
Dan, Well would you explain your comment to me, if not Dianne? I have quite a few years of development experience under my belt and would like to understand what you mean by that. I have no axe to grind here and I promise not to p*** on you. ...Jake >>>>> "D" == DanH writes: D> I figured you would, and I'm not interested in getting into a D> p***ing match, so I'm not going to elaborate. D> On May 24, 11:09 am, Dianne Hackborn wrote: >> On Tue, May 24, 2011 at 8:29 AM, DanH wrote: >> > Additionally, Android, as it's currently designed, does not have >> > "legs". The process model and UI are both too restrictive to be >> > extendable to the pads and other new paradigms of the future. >> >> Care to explain that? I very much disagree. >> >> -- >> Dianne Hackborn >> Android framework engineer >> hack...@android.com >> >> Note: please don't send private questions to me, as I don't have time to >> provide private support, and so won't reply to such e-mails. All such >> questions should be posted on public forums, where I and others can see and >> answer them. D> -- D> You received this message because you are subscribed to the Google D> Groups "Android Developers" group. D> To post to this group, send email to android-developers@googlegroups.com D> To unsubscribe from this group, send email to D> android-developers+unsubscr...@googlegroups.com D> For more options, visit this group at D> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Appwidget set background and set background transparency/alpha
>>>>> "S" == String writes: S> On Wednesday, May 18, 2011 2:34:59 PM UTC+1, Nikolay Elenkov wrote: S> Doesn't RemoveViews.setImageViewBitmap() work? >> S> Yes, it does. And on Froyo and above you can also do this: S> RemoteViews.setInt(id, "setBackgroundColor", colorValue); S> Just don't try it pre-Froyo, or you'll get the dreaded "Problem loading S> widget" display. String, How does setBackgroundColor work in relation to using a background image? In other words, in my layout I specify the android:background attribute and assign it to a 9-patch image. Can I still use setBackgroundColor? Or will this only work if there is no image? ...Jake -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Appwidget set background and set background transparency/alpha
>>>>> "N" == Niall writes: N> Might be helpful for people to see the code. The preference N> (change as appropriate. My coding style is to have classes named N> with a lower first letter, so that has been changed from the link N> above): http://pastebin.com/1EkdJNnE N> Preference code: N> http://pastebin.com/r5LYfF2r N> Doing set colour (with android version check): N> http://pastebin.com/iyZEcSdM Where does the rgaView class come from? Is that from the source that you lifted from Google? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Appwidget set background and set background transparency/alpha
Thanks to both of you, I appreciate it. >>>>> "N" == Niall writes: N> Might be helpful for people to see the code. N> The preference (change as appropriate. My coding style is to have classes N> named with a lower first letter, so that has been changed from the link N> above): N> http://pastebin.com/1EkdJNnE N> Preference code: N> http://pastebin.com/r5LYfF2r N> Doing set colour (with android version check): N> http://pastebin.com/iyZEcSdM N> -- N> You received this message because you are subscribed to the Google N> Groups "Android Developers" group. N> To post to this group, send email to android-developers@googlegroups.com N> To unsubscribe from this group, send email to N> android-developers+unsubscr...@googlegroups.com N> For more options, visit this group at N> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Appwidget set background and set background transparency/alpha
>>>>> "N" == Niall writes: N> Worked perfectly. Thanks very much. I lifted this color picker N> http://code.google.com/p/color-picker-view/ and wrapped it in a N> custom preference and it works delightfully :) So your user can now use a preference option to control the background color and the transparency of that background? Would you mind sharing code or explaining what you did? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Contacts App
>>>>> "ND" == New Developer writes: ND> Hi ND> could someone explain How the Contact app creates a scroll bar ND> that displays the Alphabet as you go down ? ND> and group the contacts by first letter For this type of question I have found it very helpful to browse the open-source Android Code repository. It's a veritable wealth of information. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widget-specific Preferences
>>>>> "KV" == Kostya Vasilyev writes: KV> 3 - Each RemoteViews update needs to be self-sufficient, that is, KV> contain all the data items (setTextViewText, etc.) as well as KV> PendingIntent's. KV> Do not push separate, incremental, RemoteViews: one for text KV> views, then another for pending intents, etc. If you do, your KV> widget will stop working after a home screen orientation change KV> or if the Launcher is kicked out of memory. KV> http://kmansoft.wordpress.com/2010/05/23/widgets-and-orientation-changes/ KV> The lifetime of widget receiver does not matter here. The KV> contents of RemoteViews is saved by the launcher, and KV> PenidingIntent's are saved by "the system". KV> Finally, do not ignore onUpdate. The launcher may have its KV> reasons to rebuild the widgets, such as when the user changes the KV> phone's UI language, and maybe in other cases as well. So it *is* correct always set up the onClickPendingIntent every time I build and push update. I thought maybe I had missed something and was making a colossal error. I guess I will recode my onReceive() to actually do its work by invoking onUpdate(). This way it all works even if the system invokes onUpdate() on its own. Thanks again, Kostya, for your excellent help. This widget of mine started out as a learning exercise (I have many years of C/C++ experience but almost none with Java and none at all with Android) but one that solved a real problem. I posted the widget thinking that others might find it useful too. I now have close to 400 active users (as measured by Flurry via a once daily broadcast) and keep getting requests for enhancements. Without the help of people such as yourself (and Mark Murphy, Treking, and a few others) I never would have made it this far. Thanks! -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Timezone List
How does Android compose the list of supported timezones display when you choose "Select time zone" from the "Date & Time" preference? The TimeZone.getAvailableIDs() method returns a much larger list. I'd like to add a similar option to my code but would like have my list match Androids. If noone here knows the answer, I'd appreciate a quick pointer to how find the code in the official Android source tree. I have not yet had to jump into Android source code to look for examples but maybe this is my opportunity. Thanks. ...Jake -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widget-specific Preferences
Kostya, Hmm. Whenever the alarm in AppWidgetProvider is triggered, I have to update all widget instances as per the widget-specific preference. Based on what you have suggested, does the following make sense: 1) In the AppWidgetProvider's onReceive() method when it receives the intent from the alarm, it cycles through all valid widgetids and starts the service with an intent containing that widgetid. Actually, I can just invoke with service once with an intent containing the list of all valid widgetids. 2) The service cycles through the list of widgetids and updates each widget's remoteview using the widget-specific preference. I didn't check it just now but I'm sure I can get each widget's RemoteView and update each one separately. 3) I currently set the remoteview's onClickPendingIntent in the service. Which means I am setting it up every time the service updates the remoteview. Is that really the best way to do it? Can I set the remoteview's onClickPendingIntent in the AppWidgetProvider or, since the AppWidgetProvider regularly gets destroyed I cannot do it there? ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> Jake, KV> You can get a list of widget ids by doing something like: KV> AppWidgetManager appWidgetManager = KV> AppWidgetManager.getInstance(context); KV> ComponentName provider = new ComponentName(context, Widget.class); KV> int[] widgets = appWidgetManager.getAppWidgetIds(provider); KV> This widget id list need to be filtered for "stale" ones. KV> -- Kostya KV> 03.05.2011 23:58, Jake Colman пишет: >> Kostya, >> >> Gee, I hope I'm not revealing my ignorance here... >> >> I build my RemoteViews in an IntentService. I suppose I have to find a >> way to pass the widgetid into the Intent that is used to start the >> service. If the service knows the widgetid, it can putExtra that >> widgetid into the Intent used to start the Preference Activity. >> >> So now the question is how to get widgetid ID from the AppWidgetProvider >> to the IntentService. onUpdate() is passed the appWidgetIds that need >> to be updated. I, however, do not use that method for anything. >> Instead, I use alarms to trigger my updates since I am updating every 60 >> seconds in one instance or every 24 hours in another. Currently my >> alarms send an Intent that is processed by the AppWidgetProvider's >> onReceive() method. That method does not get a widgetid. Any idea how >> I can get the set of widgetids to be updated if Android has no passed it >> to me in onUpdate? >> >> ...Jake KV> -- KV> Kostya Vasilyev -- http://kmansoft.wordpress.com KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@googlegroups.com KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widget-specific Preferences
Kostya, Gee, I hope I'm not revealing my ignorance here... I build my RemoteViews in an IntentService. I suppose I have to find a way to pass the widgetid into the Intent that is used to start the service. If the service knows the widgetid, it can putExtra that widgetid into the Intent used to start the Preference Activity. So now the question is how to get widgetid ID from the AppWidgetProvider to the IntentService. onUpdate() is passed the appWidgetIds that need to be updated. I, however, do not use that method for anything. Instead, I use alarms to trigger my updates since I am updating every 60 seconds in one instance or every 24 hours in another. Currently my alarms send an Intent that is processed by the AppWidgetProvider's onReceive() method. That method does not get a widgetid. Any idea how I can get the set of widgetids to be updated if Android has no passed it to me in onUpdate? ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> Jake, KV> You have the widget id where you're building your RemoteViews and KV> setting the PendingIntent for the click. KV> So the only thing is how to get the widget id into the KV> PendingIntent, so you can retrieve it later in the config KV> activity. KV> Probably the easiest way is to use the same extra, KV> AppWidgetManager.EXTRA_APPWIDGET_ID, as used for new widgets. Or KV> some other, as you see fit. KV> To make sure that you get multiple PendingIntent objects, each KV> with its own widgetId, you can use unique reqestId values with KV> PendingIntent.getActivity, such as the widget Id itself. KV> Intent intent = new Intent(context, WidgetConfigActivity.class); KV> intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId); KV> PendingIntent pending = PendingIntent.getActivity(context, widgetId, KV> intent, KV> PendingIntent.FLAG_UPDATE_CURRENT); KV> updateViews.setOnClickPendingIntent(R.id.widget_top_level, KV> pendingIntent); KV> Might be a good idea to cancel unneeded pending intents somewhere KV> in Widget.onDeleted. KV> -- Kostya KV> 03.05.2011 17:12, Jake Colman пишет: >> Kostya, >> >> I've been noodling around thinking about this problem while >> working on other features but I'm stumped on one part of it. When >> the Preference Activity is launched as a Configuration Activity >> the intent contains widget ID. But I can also launch the same >> Activity if the user touches the widget so that the user can >> reconfigure the widget even after it has been installed. In that >> situation, how can I know which widget is being reconfigured? The >> widget ID is not part of the widget itself so I don't how I can >> grab the ID of the specific widget that is being reconfigured. >> >> ...Jake >> KV> -- KV> Kostya Vasilyev -- http://kmansoft.wordpress.com KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@googlegroups.com KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widget-specific Preferences
Kostya, I've been noodling around thinking about this problem while working on other features but I'm stumped on one part of it. When the Preference Activity is launched as a Configuration Activity the intent contains widget ID. But I can also launch the same Activity if the user touches the widget so that the user can reconfigure the widget even after it has been installed. In that situation, how can I know which widget is being reconfigured? The widget ID is not part of the widget itself so I don't how I can grab the ID of the specific widget that is being reconfigured. ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> Well, in that case you already know the widget id for a KV> particular instance of your configuration activity - it's passed KV> in as an intent extra. KV> 25.04.2011 1:21 пользователь "Jake Colman" написал: >>>>>>> "KV" == Kostya Vasilyev writes: >> KV> 24.04.2011 19:35, Jake Colman пишет: >> >> >> If I use an onClickListener() and on >> >> SharedPreferenceChangeListener() to detect specific preference >> >> clicks or changes to a preference, I can parse out the widget >> >> ID from the key so that I know which specific widget has been >> >> effected. I can then make sure that I update just that specific >> >> widget accordingly. Can you think of a better way to do that? >> KV> Umm... Sounds like you also want to present options for multiple KV> widgets at the same time within a single preference activity? >> KV> If so, I would not use the activity as the event listener. >> KV> I'd create a class that encapsulates the complete set of KV> preferences for one widget instance, serves as the event listener KV> for the involved Preference objects, and knows its associated KV> widget Id value. The activity would instantiate these objects as KV> needed, one for each widget Id. >> KV> I'd also use onPreferenceChange rather that KV> onSharedPreferenceChanged, because the former uses a Preference KV> reference you can switch on, without parsing preference keys. >> >> Actually, no. :-) >> >> I want to, for example, allow instance #1 to have a different label than >> instance #2. If I continue to use my single Preference Activity which >> has one listener for all widgets, it will need to know which widget's >> key has been changed so that it can update that instance. Hm. >> Unless I just update all instances all the time when any one instance's >> preference is changed... >> >> >> -- >> Jake Colman -- Android Tinkerer >> >> -- >> 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 KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@googlegroups.com KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Setting Widget Background via RemoteView
>>>>> "KV" == Kostya Vasilyev writes: KV> 12.04.2011 17:19, Jake Colman пишет: >> I have yet to figure this out so I though I'd try posting again. >> >> Given a widget with a background image specified in its layout, >> how can one set the background's transparency at runtime? >> >> I have tried Kostya's suggestion of calling the >> RemoteView.setInt() method and passing in setAlpha as the >> methodName but I get a reflection error. KV> Calling "setInt" for "setAlpha" works starting with 2.2 - where KV> ImageView.setAlpha is marked with @RemotableViewMethod. >> I know this is doable because other application widgets have >> sliders to set the transparency at runtime. But how? Kostya, Now I know for sure it's doable since you just released upgrades to your widgets that do it! Unfortunately, and I admit that I am being obtuse, I'm still not getting it. When I call RemoteViews.setInt(id,"setAlpha",value) what am I supposed to be passing in for the id parameter? It's not the layout id since that does not have a setAlpha method. I tried sending in the id of my background drawable but that gave me an error that it could not find the view. What's the magic incantation? Have you done a blog posting on this? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: SimpleDateFormat Problem
>>>>> "MM" == Mark Murphy writes: MM> On Sun, Apr 24, 2011 at 5:28 PM, Streets Of Boston MM> wrote: >> "Per the docs, I should be able to get a time formatted as follows": Which >> docs says that 'p' and 'a' are valid values? >> >> AM and PM are the official en-US locale strings for before noon and after >> noon. >> The 'p' and 'a' are not official locale strings for this. MM> Specifically, the docs state: MM> "Note that the count [of characters in a pattern] does not specify the MM> exact width of the field." Just because you have a single "a" does not MM> mean you get a one-character AM/PM designator. A closer read of the documentation, and googling for a different version of the same docs, make it clear that only AM/PM is supported. I guess I can use a higher level method that gives me the separate components and just build the string myself. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widget-specific Preferences
>>>>> "KV" == Kostya Vasilyev writes: KV> 24.04.2011 19:35, Jake Colman пишет: >> If I use an onClickListener() and on >> SharedPreferenceChangeListener() to detect specific preference >> clicks or changes to a preference, I can parse out the widget ID >> from the key so that I know which specific widget has been >> effected. I can then make sure that I update just that specific >> widget accordingly. Can you think of a better way to do that? KV> Umm... Sounds like you also want to present options for multiple KV> widgets at the same time within a single preference activity? KV> If so, I would not use the activity as the event listener. KV> I'd create a class that encapsulates the complete set of KV> preferences for one widget instance, serves as the event listener KV> for the involved Preference objects, and knows its associated KV> widget Id value. The activity would instantiate these objects as KV> needed, one for each widget Id. KV> I'd also use onPreferenceChange rather that KV> onSharedPreferenceChanged, because the former uses a Preference KV> reference you can switch on, without parsing preference keys. Actually, no. :-) I want to, for example, allow instance #1 to have a different label than instance #2. If I continue to use my single Preference Activity which has one listener for all widgets, it will need to know which widget's key has been changed so that it can update that instance. Hmmmmm. Unless I just update all instances all the time when any one instance's preference is changed... -- Jake Colman -- Android Tinkerer -- 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
[android-developers] SimpleDateFormat Problem
Per the docs, I should be able to get a time formatted as follows: 7:33p with a format string of "h:mma" The result, however is 7:33PM Is this a documentation bug, a "Jake" bug, or is this not possible? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widget-specific Preferences
Kostya, I like your second suggestion. So in my Preference Activity's onCreate() I should get every preference by original key name and then reset the key name to include the widget. That means I'll have a full set of non-unique preference keys without any data but that should not really be an issue. According to the docs it does not look like there is a method to iterate through "all preferences" so, instead, I'll have to get every preference by specific key name and manually change each one. Have I missed a more direct way of changing all the keys? If I use an onClickListener() and on SharedPreferenceChangeListener() to detect specific preference clicks or changes to a preference, I can parse out the widget ID from the key so that I know which specific widget has been effected. I can then make sure that I update just that specific widget accordingly. Can you think of a better way to do that? To facilitate parsing out the widget id, I have already externalized all my key names as string resources so that I can edit the string to include a ":". This way I can parse out the text that follows the ":" and get the widget id. Did you do something similar or did you not have the need to know which widgetid has had its preference changed? ...Jake >>>>> "KV" == Kostya Vasilyev writes: KV> Jake, KV> It's possible to make your subclass of PreferenceActivity use a KV> specific preference file by putting something like this inside KV> its onCreate: KV> PreferenceManager prefManager = getPreferenceManager(); KV> prefManager.setSharedPreferencesName("widget_pref_" + KV> String.valueOf(widgetId)); KV> This seems somewhat inefficient though, because each widget will KV> get its own preference storage file. KV> To use a single preference file where each widget gets its own KV> set of keys (dependent on a particular widget id), you could try KV> using Preference.setKey: KV> for preference : all Preferences in the screen { KV> String keyOriginal = preference.getKey(); KV> String keyWithWidgetId = keyOriginal + String.valueOf(widgetId); KV> preference.setKey(keyWithWidgetId); KV> } KV> Hope this helps. KV> -- Kostya KV> 24.04.2011 17:28, Jake Colman пишет: >> I currently use a Preference Activity and a preference XML file to >> manage my preferences. Since a Preference Activity handles edits >> on its own, is there still a way to use it if I need to change the >> key name at runtime to have a widget id? I am pretty sure I can >> get the widget from the intent since it is launched as a >> configuration activity but can I tap in and use it? KV> -- KV> Kostya Vasilyev -- http://kmansoft.wordpress.com KV> -- KV> You received this message because you are subscribed to the Google KV> Groups "Android Developers" group. KV> To post to this group, send email to android-developers@googlegroups.com KV> To unsubscribe from this group, send email to KV> android-developers+unsubscr...@googlegroups.com KV> For more options, visit this group at KV> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Widget-specific Preferences
I am looking to implemented widget-specific preferences in my app. I have reviewed numerous blogs and posts, including Kostya's, and am familiar with the overall approach of using the widget ID as a suffix to the preference key. I currently use a Preference Activity and a preference XML file to manage my preferences. Since a Preference Activity handles edits on its own, is there still a way to use it if I need to change the key name at runtime to have a widget id? I am pretty sure I can get the widget from the intent since it is launched as a configuration activity but can I tap in and use it? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Timezone Question
Bob, et al, Wow! Great comments and replies. Thanks! The sunrise/sunset time is given in UTC based on lat/long. As another poster said, I do have that part down pat. My only concern is with how to display the time for the correct timezone. My user has manually set his timezone because of a problem with Google calendar. He never wants the phone to know that it might have changed timezones. The phone still displays the correct time for the local timezone. His request is that since the phone knows the correct time, why is my app not displaying the "correct" time for sunset. I think I will go with one of the other poster's comments. Since the phone is being told its timezone, the app will do what its told. If it becomes important, I can always add a preference to allow a user to override the timezone setting for the app. Thanks for all the help! ...Jake >>>>> "BK" == Bob Kerns writes: BK> While one hopes he does, it's not always a good assumption. But BK> that aspect wasn't the intended focus of my remarks. BK> The point is -- the timezone SHOULD have absolutely ZERO impact BK> on the actual calculated times. BK> There are really only three ways to get an error here that I can BK> see. (Chime in if you can come up with more!) BK> * Using the wrong location. BK> * Doing the wrong calculation. BK> * Displaying with the wrong timezone (including DST errors, but that BK> shouldn't be possible as a program error that I can see). BK> A fourth possibility is a confused user; I'm not sure how to BK> break down the possibilities there -- though using a TZ with BK> different DST characteristics might be included. BK> But I think the first step in sorting out the problem is to BK> identify which problem you have, and that was why I was covering BK> the territory. I hope the OP understands that I don't know any BK> details of his knowledge or app, and can disregard any aspect of BK> my message he's confident he's adequately eliminated! BK> On Sat, Apr 23, 2011 at 8:40 AM, String wrote: >> No offense, Bob (and I do mean that, I value your posts on this forum), but >> I think we can safely assume that the OP knows how to calculate times of >> sunrise and sunset. He's already showing that in his app, from the sound of >> things, and is probably doing OK with that aspect. >> >> The issue at hand is how (and maybe whether) to work around a user having >> set their phone to a different zone than the one they're actually >> in. Nobody >> says this is affecting the absolute (UTC) time of sunrise/sunset in the >> calculations, it's purely about display. >> >> String >> >> >> -- >> 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 >> BK> -- BK> You received this message because you are subscribed to the Google BK> Groups "Android Developers" group. BK> To post to this group, send email to android-developers@googlegroups.com BK> To unsubscribe from this group, send email to BK> android-developers+unsubscr...@googlegroups.com BK> For more options, visit this group at BK> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Timezone Question
My app needs to know the timezone in which is executing. To do this, I have the following code: import java.util.TimeZone; TimeZone tz = TimeZone.getDefault(); One of my users says he has configured his phone to not switch timezones even though he may have flown across the country. He says the phone displays the correct local time but his calendars remain in his native timezone or "his calendars get messed up". I didn't know there was such a problem nor did I know that you can change your phone's idea of where it is. He says that my app, which calculates sunset time, is off by an hour. He is from Chicago but is currently in Florida and my app is showing Chicago time for sunset instead of the time in Florida. What API should I be using to get the timezone of the current location as opposed to the timezone that he has forced the phone to use? Thanks. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: NPE in java.util.Calendar
Thanks Mark and Andrew. The Date variable should never, ever be NULL in the first place so that didn't occur to me. I assumed I was using the API somehow incorrectly. Thanks for the help. >>>>> "ae" == andrew esh writes: ae> Test "Date SunsetTime = c.getSunset(); " to see if it is returning ae> NULL, before using it in the next line. ae> On Apr 22, 10:41 am, Jake Colman wrote: >> The code that triggers this crash is as follows: >> >> ZmanimCalendar c = new ZmanimCalendar(l); >> Date SunsetTime = c.getSunset(); >> String SunsetTimeString = >> DateFormat.getTimeInstance(DateFormat.SHORT).format(SunsetTime); >> >> What could possibly trigger an NPE in this code? Is there something I >> should be checking about SunsetTime before passing it in to be >> formatted? ae> -- ae> You received this message because you are subscribed to the Google ae> Groups "Android Developers" group. ae> To post to this group, send email to android-developers@googlegroups.com ae> To unsubscribe from this group, send email to ae> android-developers+unsubscr...@googlegroups.com ae> For more options, visit this group at ae> http://groups.google.com/group/android-developers?hl=en -- Jake Colman -- Android Tinkerer -- 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
[android-developers] NPE in java.util.Calendar
I have been getting ACRA crash reports with the following stacktrace: java.lang.NullPointerException at java.util.Calendar.setTime(Calendar.java:1284) at java.text.SimpleDateFormat.formatImpl(SimpleDateFormat.java:730) at java.text.SimpleDateFormat.format(SimpleDateFormat.java:1011) at java.text.DateFormat.format(DateFormat.java:384) at com.jnc.zmanminder.ZMUpdateService.buildUpdate(ZMUpdateService.java:117) The code that triggers this crash is as follows: ZmanimCalendar c = new ZmanimCalendar(l); Date SunsetTime = c.getSunset(); String SunsetTimeString = DateFormat.getTimeInstance(DateFormat.SHORT).format(SunsetTime); What could possibly trigger an NPE in this code? Is there something I should be checking about SunsetTime before passing it in to be formatted? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: new to andriod
>>>>> "MO" == Marcin Orlowski writes: MO> On 13 April 2011 12:52, shwet wrote: >> I m new to andriod and I want to develop a game withing 10 days , and >> also I am a php developer and know core java. >> I wanted to know how can I proceed >> MO> Further. MO> PS: good luck. even with framework. It is absolutely astounding to me how many questions of this ilk are posted to this group. I have never seen anything like this - and I have been around for a while. "I don't know anything. Please tell me how to create a killer app in 2 days". If someone is not intelligent to at least google for how to begin Android development and to install the SDK and tutorials, how do they expect to accomplish anything? Sheesh... -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Writing Version-Specific Code
>>>>> "MM" == Mark Murphy writes: MM> On Tue, Apr 12, 2011 at 5:08 PM, lbendlin wrote: >> It was also factually wrong, according to the all-knowing source of all >> wisdom (aka Wipikedia) >> >> Basically, use reflection to "hide" the new function from the >> compiler-complainer. MM> I tend to use conditional class loading more, isolating MM> version-specific code in classes that I can conditionally MM> reference when it is safe to do so. Can you provide an example? I am especially looking to understand how I can use this technique to have, for example, a preferences screen that enables/disable an option (probably with an appropriate summary text) based on OS version. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Writing Version-Specific Code
My application is targeted for v1.6 and greater. There is, however, one feature that I'd like to implement that would work only on v2.2. How does one write and publish code that will work on v1.6 yet make use of v2.2 APIs if they are available? How does one properly set up the Manifest to indicate that the app runs on v1.6 but would prefer v2.2? I read up on MinSDK but I am not clear on how it works for this purpose. An RTFM answer is fine if appropriate. Thanks. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Setting Widget Background via RemoteView
>>>>> "KV" == Kostya Vasilyev writes: KV> 12.04.2011 17:19, Jake Colman пишет: >> I have yet to figure this out so I though I'd try posting again. >> >> Given a widget with a background image specified in its layout, >> how can one set the background's transparency at runtime? >> >> I have tried Kostya's suggestion of calling the >> RemoteView.setInt() method and passing in setAlpha as the >> methodName but I get a reflection error. KV> Calling "setInt" for "setAlpha" works starting with 2.2 - where KV> ImageView.setAlpha is marked with @RemotableViewMethod. This is good to know but I'd like to be able continue targeting 1.6 devices as well. >> I know this is doable because other application widgets have >> sliders to set the transparency at runtime. But how? KV> Another option would be to change the image in your app's code, KV> by using Drawble.setAlpha. KV> It's what ImageView.setAlpha does: KV> mDrawable = mDrawable.mutate(); KV> mDrawable.setAlpha(mAlpha * mViewAlphaScale >> 8); So get the Drawable via its resource ID and mutate it? How did you come up with the arguments for setAlpha? Can you explain them, please? KV> Then you have two options: sending the image in RemoteViews over KV> RPC as a bitmap with setImageViewBitmap() (probably won't work KV> for nine patches, and/or might need explicit bounds values set KV> first) or saving it to a temporary file and using KV> setImageViewUri. Its a 9-patch so I'll go with setImageViewUri. A dumb question: setting the image view has the effect of resetting the layout's background attribute? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Setting Widget Background via RemoteView
>>>>> "KV" == Kostya Vasilyev writes: >> Given that its usually Kostya that answers my widget questions >> (thanks, Kostya!) it looks like there may be a paucity of widget >> authors frequenting this group. But I figure there is no harm in >> trying again. KV> Ok, that's pretty much all I have to say about this. I'll keep KV> quiet now, hoping for someone more knowledgeable to answer :) I hope you realize I was being complimentary, not critical. I very much appreciate all your help. With respect to my widget-specific questions you are pretty much the only one that does! Now let me go back and re-read your post and see what I can do. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Setting Widget Background via RemoteView
I have yet to figure this out so I though I'd try posting again. Given a widget with a background image specified in its layout, how can one set the background's transparency at runtime? I have tried Kostya's suggestion of calling the RemoteView.setInt() method and passing in setAlpha as the methodName but I get a reflection error. I know this is doable because other application widgets have sliders to set the transparency at runtime. But how? Given that its usually Kostya that answers my widget questions (thanks, Kostya!) it looks like there may be a paucity of widget authors frequenting this group. But I figure there is no harm in trying again. Thanks! ...Jake -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widgets: Lanscape vs Portrait
>>>>> "KV" == Kostya Vasilyev writes: KV> [ below ] KV> 09.04.2011 0:12, Jake Colman пишет: >>>>>>> >>>>> "KV" == Kostya Vasilyev writes: KV> 08.04.2011 19:25, Jake Colman пишет: >> >> >> I have a 2x1 widget with two textviews, aligned top and bottom >> >> to the baseline, that display fine in Portrait. When I switch >> >> to landscape, there is insufficient room for the two textviews >> >> (the widget becomes long and narrow) so the two textviews >> >> overlap each other. >> >> [snip] >> KV> I'd keep both text views in both layout, using visibility="gone" KV> where a view is not supposed to show - just to be safe. >> KV> You could also use one text view, combining data from your KV> original two, in landscape mode. In that case, you'd have a total KV> of three views, and make portrait-only views "gone" in the KV> landscape layout, and vise versa. >> >> But if onUpdate is not called on changes to orientation, how do >> you know >> a) which layout to reference and b) which visibility to make "gone"? >> KV> Jake, KV> That's my point exactly - you don't know, and shouldn't care, KV> because you switch layouts in the .xml, not from code. KV> The RemoteViews in your code needs to cover both KV> orientations. You do this by using the same layout name (resource KV> id) for both portrait and landscape orientations, let's say one KV> in res/layout, and the other in res/layout-land. KV> Now you have two .xml layout files, which, because of having the KV> same name, are two versions of the same layout. Same as for KV> regular (non-widget) layouts, really. Put text views with the KV> same IDs into those .xml files, and mark them as visible and gone KV> as needed. KV> Your RemoteViews will have a layout resource ID that common to KV> both portrait and landscape .xml's, but which of those two KV> layouts is loaded will depend on home screen orientation - just KV> like with regular Activity type layouts. KV> If home screen orientation is changed, the home screen app will KV> go through the usual activity orientation change cycle, and, KV> based on the same resource ID, will load the layout appropriate KV> for the new orientation. Same as for non-widget activities in any KV> application. KV> As for putting data into text views - your code should always KV> specify values for all text views used in both orientations, KV> because a view that's "gone" now can become "visible" after a KV> home screen orientation change. KV> -- Kostya Kostya, This worked perfectly. Thanks! ...Jake -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Widgets: Lanscape vs Portrait
>>>>> "KV" == Kostya Vasilyev writes: KV> 08.04.2011 19:25, Jake Colman пишет: >> I have a 2x1 widget with two textviews, aligned top and bottom to >> the baseline, that display fine in Portrait. When I switch to >> landscape, there is insufficient room for the two textviews (the >> widget becomes long and narrow) so the two textviews overlap each >> other. KV> Yep, there is typically less per-widget height in landscape mode. KV> One way to handle this is to use Launcher shortcut - sized KV> widgets, but those are pretty small. Making larger widgets KV> requires some more work: Yup, I plan on making a 1x1 widget available as well. >> What is the correct way to handle this? >> >> Do I need a create a 2x1 landscape layout so that Android will use >> that specific layout instead of reusing my one layout? KV> Yes, make a landscape version with the same name in res/layout-land. >> If so, and if that new layout uses one textview instead of two, >> how do I know at runtime which layout is being used? KV> You don't - especially since onUpdate doesn't get called for KV> widget orientation changes. So whatever you push out into the KV> widget with RemoteViews has to work for both orientations. KV> Resources do get reloaded though, so you can rely on resource KV> qualifiers like -land, etc. >> Or do I keep the code the same and uses the same IDs on both >> layouts and updating that second textview id won't hurt anything? KV> I'd keep both text views in both layout, using visibility="gone" KV> where a view is not supposed to show - just to be safe. KV> You could also use one text view, combining data from your KV> original two, in landscape mode. In that case, you'd have a total KV> of three views, and make portrait-only views "gone" in the KV> landscape layout, and vise versa. But if onUpdate is not called on changes to orientation, how do you know a) which layout to reference and b) which visibility to make "gone"? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Widgets: Lanscape vs Portrait
I have a 2x1 widget with two textviews, aligned top and bottom to the baseline, that display fine in Portrait. When I switch to landscape, there is insufficient room for the two textviews (the widget becomes long and narrow) so the two textviews overlap each other. What is the correct way to handle this? Do I need a create a 2x1 landscape layout so that Android will use that specific layout instead of reusing my one layout? If so, and if that new layout uses one textview instead of two, how do I know at runtime which layout is being used? Or do I keep the code the same and uses the same IDs on both layouts and updating that second textview id won't hurt anything? -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Amazon Market Stats down still - please everybody report it to them
>>>>> "n" == niko writes: n> Ugh, the Amazon market stats have been down almost a week now. I n> mean only five days in and the stats are down already. n> If everyone gets together and files reports perhaps it will n> "encourage" them to fix this problem more quickly. Do you really think that Amazon is not already aware of this problem and that Developers won't be happy? Flooding them with emails will only take up more of their valuable time. IMHO. -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: new developer questions
Have you tried googling any of your questions? It's much faster and it will allow you to ask much more targeted questions. >>>>>writes: > where can i download ADT Plugin for Eclipse? > On Apr 5, 11:40 am, hoss7 wrote: >> how can i test my app in phone? >> >> On Apr 5, 12:26 am, dana tassler wrote: >> >> >> >> >> >> >> >> > A key to becoming an effective programmer is using the internet >> > effectively. >> >> > Using Google, I searched for "develop android" and got this page. I'd >> > recommend being resourceful and not afraid to look for answers on your >> > own. Yes, a forum is for assistance but if you post a request for >> > help yesterday and another today, that won't speed up replies (it's >> > like mashing the button for an elevator). >> >> > You may also consider polishing up your English a bit, you may find >> > you get more responses. For instance, you said: >> >> > "1.best ide for develop android app?" >> >> > You could have instead written "What is the best IDE for developing >> > android applications?" >> >> > I think google translator may help you. >> >> > Best of luck. >> >> > On Apr 4, 2:56 am, hoss7 wrote: >> >> > > 1.best ide for develop android app? >> > > 2.how and where can i start for develop? >> > > 3.what i need for run and test app in my pc? >> > > 4.is android develop easy or not? >> >> > > i am Computer engineering and web developer > -- > 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 -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: new developer questions
Have you tried googling any of your questions? It's much faster and it will allow you to ask much more targeted questions. >>>>>writes: > how can i test my app in phone? > On Apr 5, 12:26 am, dana tassler wrote: >> A key to becoming an effective programmer is using the internet >> effectively. >> >> Using Google, I searched for "develop android" and got this page. I'd >> recommend being resourceful and not afraid to look for answers on your >> own. Yes, a forum is for assistance but if you post a request for >> help yesterday and another today, that won't speed up replies (it's >> like mashing the button for an elevator). >> >> You may also consider polishing up your English a bit, you may find >> you get more responses. For instance, you said: >> >> "1.best ide for develop android app?" >> >> You could have instead written "What is the best IDE for developing >> android applications?" >> >> I think google translator may help you. >> >> Best of luck. >> >> On Apr 4, 2:56 am, hoss7 wrote: >> >> >> >> >> >> >> >> > 1.best ide for develop android app? >> > 2.how and where can i start for develop? >> > 3.what i need for run and test app in my pc? >> > 4.is android develop easy or not? >> >> > i am Computer engineering and web developer > -- > 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 -- Jake Colman -- Android Tinkerer -- 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
[android-developers] Re: Layout Question
>>>>> "PW" == Phill Wiggin writes: PW> On Mon, Apr 4, 2011 at 3:54 PM, Jake Colman wrote: >> >> >> No takers on this question? Any reason why word-wrapped text won't honor >> the layout_centerInParent directive? >> >> PW> I haven't used centerInParent and I'm not at my desk to try, but PW> that sounds like it's trying to center your TextView inside the PW> parent Relative Layout... Not center the text in the PW> TextView. Try android:gravity="center". PW> http://developer.android.com/reference/android/widget/TextView.html#attr_android:gravity PW> Not sure if it'll work when your text wraps (since your text PW> isn't "smaller than the view"). Bingo! Thanks! I wasn't thinking of the difference between specifying the alignment of the views relative to one another and the alignment of the text inside of a view. -- Jake Colman -- Android Tinkerer -- 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