android - why is BroadcastReceiver called twice from the OnPostExecute in asystask? -
the question simple created broadcaster class in fragrment class. , call asystask class perform. after execute class (on onpostexecute method), send broadcaster intent fragment class once.
however, result got onreiver method 2 times. (i verified using log got onpostexecute method , send broadcaster once, onreiver method triggered twice). can give me help. bugs me , wasted time. thank you
public class fragment extends fragment{ @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { currentview = inflater.inflate(r.layout.left_panel, container, false); mcontext = currentview.getcontext(); init(); return currentview; } @override public void onresume(){ super.onresume(); localbroadcastmanager.getinstance(getactivity()).registerreceiver(albumlistbroadcaster, new intentfilter(commonutilities.broadcasterofalbumtitlelist)); } private void init(){ albumlistbroadcaster = new albumlistbroadcaster(); setonclickbuttonsevent(); clearbtn(); } public void setonclickbuttonsevent(){ //modifybtn.setonclicklistener(new modifyaccountbtnlistener()); modifybtn.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { intent intent = new intent(mcontext, webactivity.class); startactivityforresult(intent, requestcode); } }); } @override public void onactivityresult(int requestcode, int resultcode, intent intentdata) { // todo auto-generated method stub if(requestcode == requestcode){ if(resultcode == result_ok){ //sendbroadcaster(); data = this.getactivity().getsharedpreferences(commonutilities.sharedpreferenceurl, 0); string userttoken = data.getstring("usertoken", ""); string mobileuserid = data.getstring("mobileuserid", ""); string services = intentdata.getstringextra("servicesjsonarray"); try { jsonarray socialmedias = new jsonarray(services); log.d("socialmedias", socialmedias.tostring()); clearbtn(); //jsonarray accountinfo = new jsonarray(services); mdisplaypiconalbumfragment.ondisplaypiconalbumfragment(new jsonarray()); if(socialmedias.length() > 0){ totalarrayforalbum = new jsonarray(); int lastnum = socialmedias.length(); for(int = 0;i< lastnum;i++){ jsonobject 1 = socialmedias.getjsonobject(i); string socialname = one.getstring("service_display_name"); activatebtn(i,socialname); string servicename = one.getstring("service_name"); map <string,string> map = new hashmap<string,string>(); map.put("usertoken", userttoken); map.put("userid", mobileuserid); map.put("servicename", servicename); new requestalbums(map,getactivity()).execute(commonutilities.albumlisturl); } }else{ arraylist<string> emptyarr = new arraylist<string>(); emptyarr.add(getstring(r.string.emptylist)); createmenu(emptyarr); } } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } } } super.onactivityresult(requestcode, resultcode, intentdata); } public class albumlistbroadcaster extends broadcastreceiver{ string title = ""; @override public void onreceive(context context, intent intent) { log.d("onrecive","i here"); } } public class requestalbums extends asynctask<object,object,string>{ private httpentity httpentity; private httpget httpget; private httpclient httpclient; private inputstream inputstream; private httpresponse httpresponse; private map<string,string> param; private context mcontext; public requestalbums(map<string,string> param,context c){ this.param = param; mcontext = c; } @override protected void onpreexecute(){ // todo auto-generated method stub super.onpreexecute(); } @override protected void onpostexecute(string result) { // todo auto-gworkenerated method stub log.d("background", result); arraylist<string> resultarr = getonlytitle(result); intent intent = new intent(commonutilities.broadcasterofalbumtitlelist); intent.putstringarraylistextra("titlelist", resultarr); intent.putextra("resultinfo", result); //intent.putextra("titlelist", resultarr.tostring()); localbroadcastmanager.getinstance(mcontext).sendbroadcast(intent); //super.onpostexecute(result); } @override protected string doinbackground(object... input) { --- } }
have noticed have sendbroadcast() function being called in onactivityresult?
@override public void onactivityresult(int requestcode, int resultcode, intent intentdata) { // todo auto-generated method stub if(requestcode == requestcode){ if(resultcode == result_ok){ sendbroadcaster();
Comments
Post a Comment