WIllJBD
WIllJBD

Reputation: 6164

A Static Class to hold information through multiple activities

I am building an app with a pretty decent UI, and thus has multiple activities and classes. Most of the classes are relative to a single activity or single other class, how ever: I need to create a "class" that can store/pass information and perform functions from multiple other activites and classes.

I am worried that when I create a new object of the "class" in each other activity/class that it will erase or call a new instance for this "class", where as I need the data to stay put while I go from activity to activity, to be able to be called upon and used/changed, and be acessible throughout the application.

Is there any special way to do this?

Thank you.

Upvotes: 2

Views: 403

Answers (2)

mre
mre

Reputation: 44240

Do not implement the singleton design pattern; this is the reason for listeners. A UI component registers a bunch of listeners (i.e. model and/or controller objects). When an event occurs, listeners are notified and update their state accordingly. There is no reason to delegate the handling of messages to a proxy object, such as the singleton in this case.

Singleton pattern: Drawbacks

Upvotes: 0

Its not blank
Its not blank

Reputation: 3095

you can use sharedpreferences .If you dont have many variable else create a class with all

public static "variables";

Upvotes: 1

Related Questions