Skip to content

Instantly share code, notes, and snippets.

@jmhend
Created July 3, 2013 19:04
Show Gist options
  • Select an option

  • Save jmhend/5921760 to your computer and use it in GitHub Desktop.

Select an option

Save jmhend/5921760 to your computer and use it in GitHub Desktop.
Exactly how dangerous is this?
// 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