2

In my main Activity I have object with some data in it. I want to delete all this data through PreferenceActivity using method (wipe()) that does this job. How can I do it?

Illustration

Inside Preferences.java there is a OnPreferenceClickListener which, when activated, expected to use method in object that I need to access.

Thanks in advance.

1 Answer 1

3

Just make this object as static.

Then you can access to this object by class name.

Activity.counters.wipe(); 

But, keeping data in activities is a bad practice in android development

Sign up to request clarification or add additional context in comments.

1 Comment

I know two ways, but it may be more. First, you can contain data in Application class developer.android.com/reference/android/app/Application.html .Second, if your need only one Counters object you may made it as singletone. And contain data in Counters class as private static field with accessors. Hope, I help you, Roman. If you have more questions you may mail me and speak with me in russian :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.