Monday, April 14, 2014

Fragment needs and service communications with broadcasting how to achieve?


fragment can not be directly sendBroadcast ();. getActivity () sendBroadcast (), then the error.
How to achieve fragment and service broadcasting?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Service to try to bind the way, have not tried broadcasting, broadcasting feeling relatively inefficient
Reply:
fragment is to be among the parasite in some Activity, if you want to send a broadcast Fragment inside, it will only send it in the Activity on the inside, getActivity (). sendBroadcast () how the error? Look up questions based on exceptions, or posted
Reply:
cited a floor DrSmart reply:
service to try to bind the way, have not tried broadcasting, broadcasting feeling relatively inefficient

Broadcast inefficient it? I do not know, I generally use the broadcast. Communication with the Service generally what method you use?
Reply:
reference to the second floor wangduanqing5945 reply:
fragment is a parasitic Activity which must, if you want to send a broadcast in Fragment inside, that it can only sent it in the Activity inside, getActivity (). sendBroadcast () how the error? According exception information look up the problem, or posted

Activity activity = getAcitivity ();
activity.sendBroadcast (intent);
Is so written, reported a null pointer error seems ~
Now the code changed, switch interfaces, run by ~
Like online tutorials getActivity () are so used:. GetActivity () findViewById () ...
Reply:
I'm sorry, these days not on CSDN, solved the problem then I do not grumble crooked

No comments:

Post a Comment