Re: [android-developers] Global Variables

2011-03-11 Thread Brill Pappin
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

Re: [android-developers] Global Variables

2011-03-11 Thread Brill Pappin
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

Re: [android-developers] Global Variables

2011-03-11 Thread Brill Pappin
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

Re: [android-developers] Global Variables

2011-03-11 Thread Kostya Vasilyev
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

[android-developers] Global Variables

2011-03-09 Thread David Williams
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

Re: [android-developers] Global Variables

2011-03-09 Thread TreKing
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.

Re: [android-developers] Global Variables

2011-03-09 Thread Justin Anderson
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

Re: [android-developers] Global Variables

2011-03-09 Thread David Williams
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

Re: [android-developers] Global Variables

2011-03-09 Thread Justin Anderson
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

Re: [android-developers] Global Variables

2011-03-09 Thread Chris Stewart
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

Re: [android-developers] Global Variables

2011-03-09 Thread Justin Anderson
* 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

Re: [android-developers] Global Variables

2011-03-09 Thread TreKing
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

Re: [android-developers] Global Variables

2011-03-09 Thread Kostya Vasilyev
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

Re: [android-developers] Global Variables

2011-03-09 Thread David Williams
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

Re: [android-developers] Global Variables

2011-03-09 Thread David Williams
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; } }

Re: [android-developers] Global Variables

2011-03-09 Thread Miguel Morales
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

Re: [android-developers] Global Variables

2011-03-09 Thread David Williams
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 .

Re: [android-developers] Global Variables

2011-03-09 Thread Miguel Morales
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

Re: [android-developers] Global Variables

2011-03-09 Thread Justin Anderson
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

[android-developers] Global variables

2009-03-28 Thread Zhubham
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