{"action":"created","issue":{"url":"https://api.github.com/repos/JoanZapata/android-asyncservice/issues/2","labels_url":"https://api.github.com/repos/JoanZapata/android-asyncservice/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/JoanZapata/android-asyncservice/issues/2/comments","events_url":"https://api.github.com/repos/JoanZapata/android-asyncservice/issues/2/events","html_url":"https://github.com/JoanZapata/android-asyncservice/issues/2","id":54454200,"number":2,"title":"@ApplicationContext doesn't work with fragments.","user":{"login":"s0nerik","id":5076429,"avatar_url":"https://avatars.githubusercontent.com/u/5076429?v=3","gravatar_id":"","url":"https://api.github.com/users/s0nerik","html_url":"https://github.com/s0nerik","followers_url":"https://api.github.com/users/s0nerik/followers","following_url":"https://api.github.com/users/s0nerik/following{/other_user}","gists_url":"https://api.github.com/users/s0nerik/gists{/gist_id}","starred_url":"https://api.github.com/users/s0nerik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s0nerik/subscriptions","organizations_url":"https://api.github.com/users/s0nerik/orgs","repos_url":"https://api.github.com/users/s0nerik/repos","events_url":"https://api.github.com/users/s0nerik/events{/privacy}","received_events_url":"https://api.github.com/users/s0nerik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-01-15T14:23:36Z","updated_at":"2015-03-05T06:50:51Z","closed_at":null,"body":"Service field annotated with @ApplicationContext is null when injecting service into fragment.\r\n\r\nHere's code from fragment:\r\n```\r\n    @InjectService\r\n    PdfGeneratorService pdfGeneratorService;\r\n\r\n    @Override\r\n    public void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        AsyncService.inject(this);\r\n    }\r\n\r\n    @Override\r\n    public void onDestroy() {\r\n        super.onDestroy();\r\n        AsyncService.unregister(this);\r\n    }\r\n```\r\n\r\nPdfGeneratorService:\r\n```\r\n@AsyncService\r\npublic class PdfGeneratorService {\r\n\r\n    @ApplicationContext\r\n    static Context context;\r\n\r\n    public File generateClassRecordsTable(List<Student> students) {\r\n        return new ClassTableCreator(context, students, context.getFilesDir()).create();\r\n    }\r\n\r\n}\r\n\r\n```\r\n\r\nFurther investigation lead me to AsyncService.java, and here's the code that supposed to get Application context from object.\r\n```\r\n    /**\r\n     * If the given object contains an Android context, extract\r\n     * the application context and retain it statically.\r\n     */\r\n    private static void extractContextFromObject(Object object) {\r\n        if (context == null && object instanceof Context) {\r\n            context = ((Context) object).getApplicationContext();\r\n        }\r\n    }\r\n```\r\n\r\nBut fragments doesn't have context, so I need to have a way to pass some context while injecting into fragment. Maybe some kind of builder approach for this would be better for this?"},"comment":{"url":"https://api.github.com/repos/JoanZapata/android-asyncservice/issues/comments/77315708","html_url":"https://github.com/JoanZapata/android-asyncservice/issues/2#issuecomment-77315708","issue_url":"https://api.github.com/repos/JoanZapata/android-asyncservice/issues/2","id":77315708,"user":{"login":"htekgulds","id":6371054,"avatar_url":"https://avatars.githubusercontent.com/u/6371054?v=3","gravatar_id":"","url":"https://api.github.com/users/htekgulds","html_url":"https://github.com/htekgulds","followers_url":"https://api.github.com/users/htekgulds/followers","following_url":"https://api.github.com/users/htekgulds/following{/other_user}","gists_url":"https://api.github.com/users/htekgulds/gists{/gist_id}","starred_url":"https://api.github.com/users/htekgulds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/htekgulds/subscriptions","organizations_url":"https://api.github.com/users/htekgulds/orgs","repos_url":"https://api.github.com/users/htekgulds/repos","events_url":"https://api.github.com/users/htekgulds/events{/privacy}","received_events_url":"https://api.github.com/users/htekgulds/received_events","type":"User","site_admin":false},"created_at":"2015-03-05T06:50:51Z","updated_at":"2015-03-05T06:50:51Z","body":"Thanks a lot! Your work is appreciated :)"}}