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 XXXXXXXXXXXX.
>  ------------------------------
>
> 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> 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 = "XXXXXXXXXXXX";
>>
>>     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> 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@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

<<image/png>>

Reply via email to