Blog Archives
Android Global Variables.
Those of you familiar with android programming will be used to using intents to pass data from activity to activity but there is a much easier way of storing state information. Using a global variable class.
1. Create a class
public class GlobalVariables extends Application { public String sResult = ""; }
This extends the application class.
Then edit your AndroidManifest.xml file
<application android:name="GlobalVariables" android:theme="@style/CustomTheme" android:label="@string/app_name" android:icon="@drawable/icon" >
When you want access to one of those juicy globals in your application just use:-
GlobalVariables gb = ((GlobalVariables) getApplicationContext()); Log.i("Test Variable is "+gb.sResult);
Simples!