android intent has other flags -
i new android developing , looking @ code of guy worked here before. check connect server. works great (see d/connectivitychecker(29802): isonline=true). create new intent , set flag (public static int online_flag = 1) can see in intent.setflags 1. send intent via sendbroadcast connectionchangereceiver.
and if read out intents flag not 1 17!
this code of connectionchangereceiver:
/** * receives notifications connectivity changes */ private broadcastreceiver connectionchangereceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { log.d("connectionchangereceiver","intent.flags(): '" + intent.getflags() + "' icm.online_flag: '" + internetconnectionmanager.online_flag+"'"); setonlinemode(intent.getflags() == icm.online_flag); } };
this logcat:
05-08 14:28:05.615: v/icm(29802): checkconnectivity 05-08 14:28:05.615: v/icm(29802): connectivitychecker.execute() 05-08 14:28:05.620: d/connectivitychecker(29802): doinbackground 05-08 14:28:05.620: d/connectivitychecker(29802): host: 192.168.2.109 port:8000 05-08 14:28:05.670: v/icm(29802): checkconnectivity 05-08 14:28:08.670: d/connectivitychecker(29802): isonline=true 05-08 14:28:08.670: d/connectivitychecker(29802): intent.setflags 1 05-08 14:28:08.670: d/connectivitychecker(29802): sendbroadcast(intent) 05-08 14:28:08.675: d/connectionchangereceiver(29802): intent.flags(): '17' icm.online_flag: '1'
the intentflag set connectivitychecker 1 connectionchangereceiver gets 17. , dont know why?
i check twice. part of code intent created , function setflags() called. variable online_flag set "public static int online_flag = 1;" same variable can call icm.online_flag.
i dont know why intent's flag 17 ??
maybe can me fix it.
edit: sorry forgot code create intent:
private class connectivitychecker extends asynctask<void, void, void> { @override protected void doinbackground(void... params) { log.d("connectivitychecker","doinbackground"); socket socket = null; boolean online = false; try { log.d("connectivitychecker","host: "+connectionhandler.host+" port:"+connectionhandler.port); socket = new socket(); socket.bind(null); inetsocketaddress address = new inetsocketaddress(connectionhandler.host, connectionhandler.port); socket.connect(address, timeout * 1000); online = socket.isconnected(); socket.close(); } catch (ioexception e) { // nothing since interested in // availability of server } log.d("connectivitychecker"," isonline=" + online); log.d("connectivitychecker"," new intent (" + connectivity_action+")"); intent intent = new intent(connectivity_action); if (online){ intent.setflags(online_flag); log.d("connectivitychecker","intent.setflags " + online_flag); } isserveravailable = online; log.d("connectivitychecker","sendbroadcast(intent)"); sendbroadcast(intent); return null; } };
setflag() , getflags() specialized flags, not custom boolean data. in case need use
intent.putextra ( "tag", boolean_flag_sent );
and in receiving place
boolean_flag_received = intent.getbooleanextra( "tag", false );
Comments
Post a Comment