Created
July 3, 2013 19:04
-
-
Save jmhend/5921760 to your computer and use it in GitHub Desktop.
Exactly how dangerous is this?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MyApplication.java | |
| public class MyApplication extends Application { | |
| private MyApplication sInstance; | |
| @Override | |
| public void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| init(this); | |
| } | |
| private static void init(MyApplication app) { | |
| sInstance = app; | |
| } | |
| public static MyApplication getInstance() { | |
| return sInstance; | |
| } | |
| } | |
| // SomeActivity.java | |
| public class SomeActivity extends Activity { | |
| @Override | |
| public void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| SomeObject o = new SomeObject(); | |
| o.doWork(); | |
| } | |
| } | |
| // SomeObject.java | |
| public class SomeObject { | |
| public void doWork() { | |
| // ... | |
| MyApplication app = MyApplication.getInstance(); | |
| // ... | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment