Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I've been researching ways to store global settings for my Android application and so far the best way seems to extend the Application class and store the shared data inside it, as described here.</p> </blockquote> <p>Except that you're not doing that.</p> <blockquote> <p>I've discovered that instead of using (CustomApplicationClass)getApplicationContext().getSomething() i can do the same thing by referencing directly to the static method inside the class like this: CustomApplicationClass.getSomething() and both ways work just fine.</p> </blockquote> <p>Of course. You could just as easily had <code>CustomApplicationClass</code> extend <code>Object</code>, then executed <code>CustomApplicationClass.getSomething()</code>. You are gaining nothing by your current approach versus just using an ordinary singleton pattern in Java, and you are losing flexibility, as an application can only have one custom subclass of <code>Application</code>.</p> <blockquote> <p>Is the second way safe to use, or is it inadvisable?</p> </blockquote> <p>The first way is pointless, since your data member and methods are static.</p> <p>Either:</p> <ol> <li><p>Make your stuff in <code>CustomApplicationClass</code> <em>not</em> be <code>static</code>, and then use <code>getApplicationContext()</code>.</p></li> <li><p>Refactor <code>CustomApplicationClass</code> to not extend <code>Application</code>, and then use the static data member and/or accessor methods, or switch more formally to <a href="http://www.techrepublic.com/blog/programming-and-development/using-the-singleton-pattern-in-java/449" rel="nofollow">the Java singleton pattern</a>.</p></li> </ol> <p>Personally, I would go with option #2.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload