java - How to access service in activity from fragment as soon as it's ready? -



java - How to access service in activity from fragment as soon as it's ready? -

i have fragmentactivity, , i'm binding service in onresume method. have fragment gets added activity. fragment phone call service doinbackground method in asynctask initialization first, , after initialization, button in fragment become enabled. when tried execute asynctask fragment's onactivitycreated or onresume method, nullpointerexception when trying service.

@override public void onresume() { new asynctask<void, void, boolean>() { @override protected boolean doinbackground(void params) { homecoming activity.getmyservice().dosomeinit(); // getmyservice() returns null } @override protected void onpostexecute(boolean result) { somebutton.enabled(result); } }.execute(); }

the activity connect service, how can tell fragment service ready used (and hence no longer null)?

i assume setting variable activity getactivity() fragment @ point. guess fragment has not been attached when , activity null , not getmyservice()

java android android-fragments android-asynctask

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -