Re: [android-developers] Global Variables
I'm not positive about this, but I think i just ran into a bug using static vars. I'm trying to fix it now, but I think my vars are getting GC'ed as the phones runs low on memory and reinitialized when I need them again. Which of course means that they get reinitialized to the default value when created. which cases the bug in my app (its a long running app). Like I said, I'm not yet positive thats the cause of my own trouble, but I think you might want to be careful about storing primitive values in static vars. -- 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
Re: [android-developers] Global Variables
To clarify, that's *not* an Android or Java bug, but a bug in my own code :) -- 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
Re: [android-developers] Global Variables
Yah, but those woud be static final :) not global vars, but constants. -- 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
Re: [android-developers] Global Variables
What probably happens us that the process gets killed and then relaunched. The relaunch may execute a code sequence different from when your app is launched for debugging or from the Launcher (i.e. main activity first), and your code that initializes and uses those globals may be sensitive to that. 12.03.2011 8:16 пользователь Brill Pappin br...@pappin.ca написал: -- 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] Global Variables
All, What is the best way of going about setting up global variables? There will be like 5-6 global variables that I would like to set when my app is launched that are then available for any code anywhere in my app. I did something similar to this under Mojo on WebOS. I just set some global variables during the stage-assistant.js script that could then be used by any script. TIA. -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddie http://www.dtw-consulting.com/GolfCaddie | Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. -- 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
Re: [android-developers] Global Variables
On Wed, Mar 9, 2011 at 2:41 PM, David Williams dwilli...@dtw-consulting.com wrote: What is the best way of going about setting up global variables? IDK about best, but easy: public static values somewhere that you set up in a custom Application class. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- 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
Re: [android-developers] Global Variables
The best way is to avoid them like the plague... If you can't then you can either subclass Application and make them available there or you can use SharedPreferences... Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Wed, Mar 9, 2011 at 1:41 PM, David Williams dwilli...@dtw-consulting.com wrote: All, What is the best way of going about setting up global variables? There will be like 5-6 global variables that I would like to set when my app is launched that are then available for any code anywhere in my app. I did something similar to this under Mojo on WebOS. I just set some global variables during the stage-assistant.js script that could then be used by any script. TIA. -- -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddiehttp://www.dtw-consulting.com/GolfCaddie| Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. -- 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 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
Re: [android-developers] Global Variables
Justin, Thanks for the information, I will have to look into just what subclassing the Application means/is and also SharedPreferences. That said, why avoid them like the plague? If you don't use global variables then just how do you get some kind of static value (which is really what I'm after) available to all aspects of your app code? TreKing, will look into the public static values as this might be more of what I need. David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddie http://www.dtw-consulting.com/GolfCaddie | Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. On 3/9/2011 3:05 PM, Justin Anderson wrote: The best way is to avoid them like the plague... If you can't then you can either subclass Application and make them available there or you can use SharedPreferences... Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Wed, Mar 9, 2011 at 1:41 PM, David Williams dwilli...@dtw-consulting.com mailto:dwilli...@dtw-consulting.com wrote: All, What is the best way of going about setting up global variables? There will be like 5-6 global variables that I would like to set when my app is launched that are then available for any code anywhere in my app. I did something similar to this under Mojo on WebOS. I just set some global variables during the stage-assistant.js script that could then be used by any script. TIA. -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddie http://www.dtw-consulting.com/GolfCaddie | Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. -- 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 mailto:android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com mailto:android-developers%2bunsubscr...@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 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 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=eninline: GClogo.png
Re: [android-developers] Global Variables
Or you can use public static like TreKing suggested... Personally, if I find that I'm having to use Global variables, then that means I'm most likely doing something wrong, and I try to restructure what I'm doing. Generally I can find a way to accomplish the same thing without them and have a better application design. Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Wed, Mar 9, 2011 at 2:05 PM, Justin Anderson magouyaw...@gmail.comwrote: The best way is to avoid them like the plague... If you can't then you can either subclass Application and make them available there or you can use SharedPreferences... Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Wed, Mar 9, 2011 at 1:41 PM, David Williams dwilli...@dtw-consulting.com wrote: All, What is the best way of going about setting up global variables? There will be like 5-6 global variables that I would like to set when my app is launched that are then available for any code anywhere in my app. I did something similar to this under Mojo on WebOS. I just set some global variables during the stage-assistant.js script that could then be used by any script. TIA. -- -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddiehttp://www.dtw-consulting.com/GolfCaddie| Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. -- 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 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
Re: [android-developers] Global Variables
I tend to do what TreKing suggested. I have a class called CommonVariables that really holds static strings for Flurry event names, the year parameter for my app (it's seasonal and changes once a year) which is used all over the place, and things like that. -- Chris Stewart http://chriswstewart.com On Wed, Mar 9, 2011 at 3:53 PM, TreKing treking...@gmail.com wrote: On Wed, Mar 9, 2011 at 2:41 PM, David Williams dwilli...@dtw-consulting.com wrote: What is the best way of going about setting up global variables? IDK about best, but easy: public static values somewhere that you set up in a custom Application class. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- 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 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
Re: [android-developers] Global Variables
* why avoid them like the plague? * Here is some light reading on the subject: http://c2.com/cgi/wiki?GlobalVariablesAreBad http://en.wikipedia.org/wiki/Global_variable http://stackoverflow.com/questions/2157685/why-no-global-variables-in-java-like-c In general, it is considered a bad coding practice... Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Wed, Mar 9, 2011 at 2:15 PM, David Williams dwilli...@dtw-consulting.com wrote: Justin, Thanks for the information, I will have to look into just what subclassing the Application means/is and also SharedPreferences. That said, why avoid them like the plague? If you don't use global variables then just how do you get some kind of static value (which is really what I'm after) available to all aspects of your app code? TreKing, will look into the public static values as this might be more of what I need. -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddiehttp://www.dtw-consulting.com/GolfCaddie| Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. On 3/9/2011 3:05 PM, Justin Anderson wrote: The best way is to avoid them like the plague... If you can't then you can either subclass Application and make them available there or you can use SharedPreferences... Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Wed, Mar 9, 2011 at 1:41 PM, David Williams dwilli...@dtw-consulting.com wrote: All, What is the best way of going about setting up global variables? There will be like 5-6 global variables that I would like to set when my app is launched that are then available for any code anywhere in my app. I did something similar to this under Mojo on WebOS. I just set some global variables during the stage-assistant.js script that could then be used by any script. TIA. -- -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddiehttp://www.dtw-consulting.com/GolfCaddie| Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. -- 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 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 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 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=enGClogo.png
Re: [android-developers] Global Variables
On Wed, Mar 9, 2011 at 3:15 PM, David Williams dwilli...@dtw-consulting.com wrote: That said, why avoid them like the plague? Global variables are one of those things, like Singletons, that on the surface seem to make life easier, then get abused like a step-child to the point of making everything worse. Used correctly, in moderation, it's often the fastest, easiest, cleanest, and most straightforward way of doing something. Like a simple flag indicating DEBUG vs RELEASE, for example. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- 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
Re: [android-developers] Global Variables
Oh, come on, guys, it's not that bad :) Sometimes I even miss a good old-fashioned goto. -- Kostya 10.03.2011 0:26, TreKing ?: On Wed, Mar 9, 2011 at 3:15 PM, David Williams dwilli...@dtw-consulting.com mailto:dwilli...@dtw-consulting.com wrote: That said, why avoid them like the plague? Global variables are one of those things, like Singletons, that on the surface seem to make life easier, then get abused like a step-child to the point of making everything worse. Used correctly, in moderation, it's often the fastest, easiest, cleanest, and most straightforward way of doing something. Like a simple flag indicating DEBUG vs RELEASE, for example. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- 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 -- Kostya Vasilyev -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Global Variables
ROFL. 10 PRINT GLOBALS ARE FINE 20 GOTO 10 Ah yes, the good old days :) David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddie http://www.dtw-consulting.com/GolfCaddie | Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. On 3/9/2011 4:01 PM, Kostya Vasilyev wrote: Oh, come on, guys, it's not that bad :) Sometimes I even miss a good old-fashioned goto. -- Kostya 10.03.2011 0:26, TreKing ?: On Wed, Mar 9, 2011 at 3:15 PM, David Williams dwilli...@dtw-consulting.com mailto:dwilli...@dtw-consulting.com wrote: That said, why avoid them like the plague? Global variables are one of those things, like Singletons, that on the surface seem to make life easier, then get abused like a step-child to the point of making everything worse. Used correctly, in moderation, it's often the fastest, easiest, cleanest, and most straightforward way of doing something. Like a simple flag indicating DEBUG vs RELEASE, for example. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- 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 -- Kostya Vasilyev --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- 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=eninline: GClogo.png
Re: [android-developers] Global Variables
Ok, trying to do this but struggling. I created a class as follows: package com.dtwconsulting.golfcaddie; import android.app.Application; public class globalVars extends Application{ public String apiKey = ; public String getApiKey() { return apiKey; } } Now, how do I get the value of the apiKey from somewhere else? Sorry, this is just my lack of knowledge on Java here. I was hoping it was something like globalVars.getApiKey(), but that doesn't seem to work. David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddie http://www.dtw-consulting.com/GolfCaddie | Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. On 3/9/2011 3:24 PM, Chris Stewart wrote: I tend to do what TreKing suggested. I have a class called CommonVariables that really holds static strings for Flurry event names, the year parameter for my app (it's seasonal and changes once a year) which is used all over the place, and things like that. -- Chris Stewart http://chriswstewart.com On Wed, Mar 9, 2011 at 3:53 PM, TreKing treking...@gmail.com mailto:treking...@gmail.com wrote: On Wed, Mar 9, 2011 at 2:41 PM, David Williams dwilli...@dtw-consulting.com mailto:dwilli...@dtw-consulting.com wrote: What is the best way of going about setting up global variables? IDK about best, but easy: public static values somewhere that you set up in a custom Application class. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- 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 mailto:android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com mailto:android-developers%2bunsubscr...@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 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 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=eninline: GClogo.png
Re: [android-developers] Global Variables
If you define to use your custom application class in the android manifest file you can get the class from your activities. Inside your activity, simple use (MyAppliction) getAppliction() and then you can access your variables. If it's static global variables you're looking for. Then you would use MyApplication.MyStaticConst On Wed, Mar 9, 2011 at 4:11 PM, David Williams dwilli...@dtw-consulting.com wrote: Ok, trying to do this but struggling. I created a class as follows: package com.dtwconsulting.golfcaddie; import android.app.Application; public class globalVars extends Application{ public String apiKey = ; public String getApiKey() { return apiKey; } } Now, how do I get the value of the apiKey from somewhere else? Sorry, this is just my lack of knowledge on Java here. I was hoping it was something like globalVars.getApiKey(), but that doesn't seem to work. -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddiehttp://www.dtw-consulting.com/GolfCaddie| Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. On 3/9/2011 3:24 PM, Chris Stewart wrote: I tend to do what TreKing suggested. I have a class called CommonVariables that really holds static strings for Flurry event names, the year parameter for my app (it's seasonal and changes once a year) which is used all over the place, and things like that. -- Chris Stewart http://chriswstewart.com On Wed, Mar 9, 2011 at 3:53 PM, TreKing treking...@gmail.com wrote: On Wed, Mar 9, 2011 at 2:41 PM, David Williams dwilli...@dtw-consulting.com wrote: What is the best way of going about setting up global variables? IDK about best, but easy: public static values somewhere that you set up in a custom Application class. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- 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 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 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 -- ~ Jeremiah:9:23-24 Android 2D MMORPG: http://solrpg.com/ http://www.youtube.com/user/revoltingx -- 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=enGClogo.png
Re: [android-developers] Global Variables
Sorry, I am new to Java and Android. I don't get what you are saying. I added the following android:name=globalVars to the manifest. But I still don't understand how I can get the value of the apiKey, which should be . David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddie http://www.dtw-consulting.com/GolfCaddie | Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. On 3/9/2011 6:16 PM, Miguel Morales wrote: If you define to use your custom application class in the android manifest file you can get the class from your activities. Inside your activity, simple use (MyAppliction) getAppliction() and then you can access your variables. If it's static global variables you're looking for. Then you would use MyApplication.MyStaticConst On Wed, Mar 9, 2011 at 4:11 PM, David Williams dwilli...@dtw-consulting.com mailto:dwilli...@dtw-consulting.com wrote: Ok, trying to do this but struggling. I created a class as follows: package com.dtwconsulting.golfcaddie; import android.app.Application; public class globalVars extends Application{ public String apiKey = ; public String getApiKey() { return apiKey; } } Now, how do I get the value of the apiKey from somewhere else? Sorry, this is just my lack of knowledge on Java here. I was hoping it was something like globalVars.getApiKey(), but that doesn't seem to work. David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddie http://www.dtw-consulting.com/GolfCaddie | Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. On 3/9/2011 3:24 PM, Chris Stewart wrote: I tend to do what TreKing suggested. I have a class called CommonVariables that really holds static strings for Flurry event names, the year parameter for my app (it's seasonal and changes once a year) which is used all over the place, and things like that. -- Chris Stewart http://chriswstewart.com On Wed, Mar 9, 2011 at 3:53 PM, TreKing treking...@gmail.com mailto:treking...@gmail.com wrote: On Wed, Mar 9, 2011 at 2:41 PM, David Williams dwilli...@dtw-consulting.com mailto:dwilli...@dtw-consulting.com wrote: What is the best way of going about setting up global variables? IDK about best, but easy: public static values somewhere that you set up in a custom Application class. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- 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 mailto:android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com mailto:android-developers%2bunsubscr...@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 post to this group, send email to android-developers@googlegroups.com mailto:android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com mailto: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 post to this group, send email to android-developers@googlegroups.com mailto:android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com mailto:android-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- ~ Jeremiah:9:23-24 Android 2D MMORPG: http://solrpg.com/ http://www.youtube.com/user/revoltingx -- You received this message because you are subscribed to the Google
Re: [android-developers] Global Variables
Ah, sorry for my brief explanation. Basically, you have to decide what you want. You can either encapsulate your application using Application sub-class which all your activities can then access. Or, you can have a java class in which you store your global variables IF they don't change at runtime. So, if you want the first option. Say you have an Application subclass named MyApp. You would add it to the manifest file like android:name=MyApp Android will use that class which you can then access from your activities using Activity.getApplication() method. So you can cast that to MyApp like so: onCreate { MyApp app = (MyApp) getApplication(); MyVar var = app.getVar(); } If you want the second option, you'd create a class called Consts.java in which you store static global variables. So something like: class Consts { public final static String AppName = SOMETHING; } Then from your activity you can access it like: String appname = Consts.AppName Also, you might want to change your font, it's a bit hard to read your messages. On Wed, Mar 9, 2011 at 4:24 PM, David Williams dwilli...@dtw-consulting.com wrote: Sorry, I am new to Java and Android. I don't get what you are saying. I added the following android:name=globalVars to the manifest. But I still don't understand how I can get the value of the apiKey, which should be . -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddiehttp://www.dtw-consulting.com/GolfCaddie| Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. On 3/9/2011 6:16 PM, Miguel Morales wrote: If you define to use your custom application class in the android manifest file you can get the class from your activities. Inside your activity, simple use (MyAppliction) getAppliction() and then you can access your variables. If it's static global variables you're looking for. Then you would use MyApplication.MyStaticConst On Wed, Mar 9, 2011 at 4:11 PM, David Williams dwilli...@dtw-consulting.com wrote: Ok, trying to do this but struggling. I created a class as follows: package com.dtwconsulting.golfcaddie; import android.app.Application; public class globalVars extends Application{ public String apiKey = ; public String getApiKey() { return apiKey; } } Now, how do I get the value of the apiKey from somewhere else? Sorry, this is just my lack of knowledge on Java here. I was hoping it was something like globalVars.getApiKey(), but that doesn't seem to work. -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddiehttp://www.dtw-consulting.com/GolfCaddie| Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. On 3/9/2011 3:24 PM, Chris Stewart wrote: I tend to do what TreKing suggested. I have a class called CommonVariables that really holds static strings for Flurry event names, the year parameter for my app (it's seasonal and changes once a year) which is used all over the place, and things like that. -- Chris Stewart http://chriswstewart.com On Wed, Mar 9, 2011 at 3:53 PM, TreKing treking...@gmail.com wrote: On Wed, Mar 9, 2011 at 2:41 PM, David Williams dwilli...@dtw-consulting.com wrote: What is the best way of going about setting up global variables? IDK about best, but easy: public static values somewhere that you set up in a custom Application class. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- 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 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 post to this group, send email to android-developers@googlegroups.com To unsubscribe from this
Re: [android-developers] Global Variables
Like this: globalVars myApp = (globalVars)getApplication(); myApp.getApiKey(); Or... since you made the variable public you can do this: myApp.apiKey; Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Wed, Mar 9, 2011 at 5:24 PM, David Williams dwilli...@dtw-consulting.com wrote: Sorry, I am new to Java and Android. I don't get what you are saying. I added the following android:name=globalVars to the manifest. But I still don't understand how I can get the value of the apiKey, which should be . -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddiehttp://www.dtw-consulting.com/GolfCaddie| Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. On 3/9/2011 6:16 PM, Miguel Morales wrote: If you define to use your custom application class in the android manifest file you can get the class from your activities. Inside your activity, simple use (MyAppliction) getAppliction() and then you can access your variables. If it's static global variables you're looking for. Then you would use MyApplication.MyStaticConst On Wed, Mar 9, 2011 at 4:11 PM, David Williams dwilli...@dtw-consulting.com wrote: Ok, trying to do this but struggling. I created a class as follows: package com.dtwconsulting.golfcaddie; import android.app.Application; public class globalVars extends Application{ public String apiKey = ; public String getApiKey() { return apiKey; } } Now, how do I get the value of the apiKey from somewhere else? Sorry, this is just my lack of knowledge on Java here. I was hoping it was something like globalVars.getApiKey(), but that doesn't seem to work. -- David Williams Check out our WebOS mobile phone app for the Palm Pre and Pixi: http://www.dtw-consulting.com/GolfCaddie Golf Caddiehttp://www.dtw-consulting.com/GolfCaddie| Golf Caddie Forum http://www.dtw-consulting.com/GolfCaddie/forum | Golf Caddie FAQ http://www.dtw-consulting.com/GolfCaddie/faq.html by DTW-Consulting, Inc. On 3/9/2011 3:24 PM, Chris Stewart wrote: I tend to do what TreKing suggested. I have a class called CommonVariables that really holds static strings for Flurry event names, the year parameter for my app (it's seasonal and changes once a year) which is used all over the place, and things like that. -- Chris Stewart http://chriswstewart.com On Wed, Mar 9, 2011 at 3:53 PM, TreKing treking...@gmail.com wrote: On Wed, Mar 9, 2011 at 2:41 PM, David Williams dwilli...@dtw-consulting.com wrote: What is the best way of going about setting up global variables? IDK about best, but easy: public static values somewhere that you set up in a custom Application class. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- 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 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 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 -- ~ Jeremiah:9:23-24 Android 2D MMORPG: http://solrpg.com/ http://www.youtube.com/user/revoltingx -- 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 post to this group, send email to
[android-developers] Global variables
Hi, Can anyone hep me with how to make a (boolean) variable global in Android? Thanks. Best Regards, Zhubham --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---