As you can probably tell from the title, I have (yet another) static reference in one of the projects that I took over, this time it’s a public static Context cont
in one of the activities that is initialized in onCreate(): cont = getApplicationContext();
This “cont” is then used in an Interactor to start an activity using a static method:
ChatActivity.startActivity(UserListingActivity.cont,user.email, FirebaseConn.senderUidNotif,FirebaseConn.senderNameNotif,user.firebaseToken);
Looking through the code, it would be quite a bit of work to get rid of this static reference. So I have two questions:
- Is it imperative to get rid of this static reference to prevent memory leaks, considering that it’s pointing to the application context which is a singleton anyway (I’m talking purely from a practical perspective, not code beauty)
- If I do have to get rid of it, can you recommend any way of easily obtaining the application context in a non-framework class (like an Interactor that doesn’t have a context)?
Thanks!