I have a separate asynctask class which creates a url for me. I tried to use an interface in the onPostExecute to send the url to my fragment, but could not managed it. I was always doing the same process in the fragments by forcing to implement the interface in onAttach.
After myTask.execute(), i simply wait for the result with a progress dialog on the screen. Everything works fine until the interface’s callback method is called.(nullpointerexception)
How can I force the fragment to make it implement the interface? (I need to send the data directly to the fragment, not via activity)
Thank you very much for your time.
Alright I found my mistake finally. As ePeace mentioned in his answer. In my Asyntask class, I created a constructor which throws nullpointerexception is the listener is null.
After that, in the fragment class, I created a listener. (Have a global reference in the class to the listener, so that you can use it on the other places in the fragment lifecycle)
And finally, in the onCreate method I created my Asyntask and gave the listener as a paramater.
Hope it works for you who might need it later. Thank you very much for your time ePeace.