Things To Know When Developing android - marwanAmeen/DroidoYem GitHub Wiki


when developing large scale app in android, in some how we need objects to be shared across the application, however this is something like a Singleton pattern, to do that in android simple First Create a global object in the android application:

public class YourApplication extends Application 
{     
     public SomeDataClass data = new SomeDataClass();
}

Then you would be able to access it all over the app.

From Activity

YourApplication appState = ((YourApplication)this.getApplication());
appState.data.UseAGetterOrSetterHere();

From Fregament

YourApplication appState
 = ((YourApplication)getActivity().getApplication());
appState.data.UseAGetterOrSetterHere();</code>

From Anywhere that receive a context

YourApplication appState= ((YourApplication)context.getApplicationContext());
appState.data.UseAGetterOrSetterHere();

More here... [http://stackoverflow.com/a/4208947/2978048)``

⚠️ **GitHub.com Fallback** ⚠️