Using roboguice without expanding activity

Is there a way to use roboguice without extending the Activity class with RoboActivity.

+4
source share
2 answers

Yes. This is easier with 1.2-SNAPSHOT, which is not yet in beta. To use 1.2, just add the following to your onCreate (), onContentChanged (), and onDestroy (). You do not need bits about EventManager if you are not using roboguice events:

@Override protected void onCreate(Bundle savedInstanceState) { RoboGuice.getInjector(this).injectMembersWithoutViews(this); super.onCreate(savedInstanceState); } @Override public void onContentChanged() { super.onContentChanged(); RoboGuice.getInjector(this).injectViewMembers(this); } @Override protected void onDestroy() { try { RoboGuice.destroyInjector(this); } finally { super.onDestroy(); } } 

If you are using RoboGuice 1.1.x (the latest stable build), then the principle is the same, but the challenges are slightly different. Take a look at the source 1.1 RoboActivity to find out what challenges you need to make.

+10
source

It works, but you have to implement RoboContext and declare it

 protected HashMap<Key<?>,Object> scopedObjects = new HashMap<>(); 
0
source

All Articles