Skip to content

Instantly share code, notes, and snippets.

@dpolishuk
Created September 29, 2015 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpolishuk/debc7d056490eef231bf to your computer and use it in GitHub Desktop.
Save dpolishuk/debc7d056490eef231bf to your computer and use it in GitHub Desktop.
@Module
public class AppModule {
private final Application application;
public AppModule(Application application) {
this.application = application;
}
@Provides public Application application() {
return application;
}
@Provides public AsyncBus asyncBus(Application app) {
MemoryInfo mi = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) app.getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
long availableMegs = mi.availMem / 1048576L;
long percentAvail = mi.availMem / mi.totalMem;
if (percentAvail > 70L) {
return new SuperPuperBus();
} else {
return new SlowMemBus();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment