Mar 12 | 7:25 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Gabriele | has entered the room |
Mark M. |
hello, Gabriele!
|
Gabriele |
hi
|
Mark M. |
how can I help you today?
|
Mar 12 | 7:30 PM |
Kevin M. | has entered the room |
Gabriele |
I've added a receiver to android.net.wifi.supplicant.CONNECTION_CHANGE
|
Mark M. |
(BTW, hello, Kevin -- be with you shortly!)
|
Gabriele |
anyway when I receive the intent and I create a new service
|
Gabriele |
the wifi can't still resolve the hostname
|
Gabriele |
why?
|
Mark M. |
I have no idea
|
Mark M. |
are you saying that hostnames resolve later, but not right at the CONNECTION_CHANGE time?
|
Gabriele |
View paste
|
Gabriele |
yes, it seems that I'm still not connected when it says I'm connected
|
Mark M. |
I have not used CONNECTION_CHANGE
|
Mark M. |
it is possible that "it is now possible to perform Wi-Fi operations" is referring to lower level things on WifiManager
|
Mark M. |
and not actual TCP/IP operations
|
Mark M. |
but that is just a guess
|
Gabriele |
ah, how can I do then? I should "active waiting" for something?
|
Mark M. |
have you considered using ConnectivityManager's broadcast instead?
|
Mar 12 | 7:35 PM |
Gabriele |
If I use it I'm sure I can send the request?
|
Gabriele |
if Yes I will
|
Mark M. | |
Mark M. |
I see more people using that than WifiManager directly for ordinary Internet work
|
Gabriele |
ok, thank you
|
Mark M. |
let me take a question from Kevin, and I will be back with you shortly
|
Mark M. |
Kevin: do you have a question?
|
Gabriele |
sure
|
Kevin M. |
Yes. I'm writing a new App using Fragments and need a way to talk to the main activity
|
Kevin M. |
In ready your book about ViewPager, that looks like a good start
|
Kevin M. |
reading
|
Mark M. |
what do you mean by "talk to the main activity"?
|
Mark M. |
what is "the main activity" with respect to your "App using Fragments"?
|
Kevin M. |
Just not sure how to handle changing the the actionbar title & menus when you go back
|
Mark M. |
the action bar items should change automatically as the fragments come and go
|
Mark M. |
the title, though, I haven't messed with
|
Kevin M. |
I have a SherlockFragmentActivity which now using a transaction (I'm having problems with using add/replace)
|
Kevin M. |
When I go back, I pop the fragment stack
|
Mar 12 | 7:40 PM |
Mark M. |
I guess I do not understand what your question is
|
Kevin M. |
It's pretty basic. I have 1 activity that will
keep going forward through different screens but be able to go back. I
want to make sure the title & menu are updated when they go back
|
Mark M. |
if you are using FragmentTransactions to move to
the different screens, use addToBackStack(), and the BACK button
processing should be automatica
|
Mark M. |
er, automatic
|
Mark M. |
with respect to the title, you can try perhaps
overriding onAttach() and onDetach() and use those to trigger changes to
the title, though I have never tried this
|
Kevin M. |
I'm using both but when I click on the back arrow in the actionbar, I handle the pop myself
|
Mark M. |
I would recommend using addToBackStack(), unless you have strong reasons to do otherwise
|
Kevin M. | |
Mark M. |
with respect to the title, the only automatic title changing that I see would be if you are using FragmentBreadCrumbs
|
Mark M. |
you should not need to do both addToBackStack() and popBackStack()
|
Kevin M. |
Not familiar with that
|
Kevin M. |
View paste
|
Mark M. |
that should be fine, even without your own popBackStack()
|
Kevin M. |
then when they hit the back button or the back arrow, I use popBackStack
|
Mar 12 | 7:45 PM |
Mark M. |
again, if the user presses the BACK button, the
last FragmentTransaction called with addToBackStack() should be
automatically popped
|
Mark M. |
without you calling popBackStack()
|
Kevin M. |
Yes, FragmentActivity handles that
|
Mark M. |
again, I do not really know what your question is
|
Kevin M. |
I need a good communication model between the activity and each fragment
|
Mark M. |
um, just call methods
|
Mark M. |
the activity knows what the current fragment is, as it executed the FragmentTransaction that set it up
|
Mark M. |
so the activity can just call methods on that fragment
|
Mark M. |
the fragment can use getActivity() to retrieve the
hosting activity and cast that to the activity's class (or an
interface) and call methods on it
|
Mark M. |
or, you are welcome to use more of a message bus approach, such as LocalBroadcastManager or Otto
|
Kevin M. |
Part of the problem is that I may have a
ListFragment that needs to start another fragment, it uses the
activity's addFragment method
|
Mar 12 | 7:50 PM |
Kevin M. |
I guess I was wondering if anyone has come up with a good framework for this communication
|
Mark M. |
I am sorry, but I do not know how to answer that beyond what I already have
|
Mark M. |
let me swing back to Gabriele, and I will be with you again shortly
|
Mark M. |
Gabriele: do you have a question?
|
Gabriele |
Now I'm using
android.net.conn.CONNECTIVITY_CHANGE, anyway how can I distinguish when
I'm connected to wifi and I can use the network?
|
Kevin M. |
I have to take off, thanks
|
Mark M. |
EXTRA_NETWORK_INFO will have a NetworkInfo telling you the connection type (WiFi, etc.)
|
Mark M. |
the NetworkInfo will also tell you the status of that connection
|
Gabriele |
if
(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION))
{NetworkInfo networkInfo =
intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
Gabriele |
then I check if connected?
|
Mark M. |
ConnectivityManager, not WifiManager
|
Mark M. |
right, the NetworkInfo has isConnected()
|
Mark M. |
and the action is android.net.conn.CONNECTIVITY_CHANGE
|
Gabriele |
yes the action is right
|
Mark M. |
(or ConnectivityManager.CONNECTIVITY_ACTION)
|
Mar 12 | 7:55 PM |
Mark M. |
Kevin: do you have another question?
|
Mark M. |
OK, if anyone has a question, go ahead
|
Mar 12 | 8:00 PM |
Gabriele |
View paste
|
Gabriele |
is this right?
|
Mark M. |
if isNoConnected is true, you would not need to continue with the rest
|
Gabriele |
yes, I've added an if with a return
|
Mark M. |
otherwise, yes, that seems about right
|
Gabriele |
anyway I'm trying this code and I'm never getting connected :O
|
Mark M. |
how are you testing it?
|
Mar 12 | 8:05 PM |
Gabriele |
I'm trying it with ide/xoom
|
Gabriele |
deactivating my wifi and enabling it
|
Mark M. |
are you getting any broadcasts at all? do you hold the ACCESS_NETWORK_STATE permission?
|
Gabriele |
yes I'm getting broadcasts
|
Gabriele |
yes I have the permission
|
Gabriele |
but every time isNoConnected is true
|
Mark M. |
oh, wait
|
Mark M. |
EXTRA_NO_CONNECTIVITY looks like it may be either true or simply not there
|
Mark M. |
hence, use false as your default
|
Gabriele |
ah
|
Mark M. |
also, that extra is only there on a disconnect event, anyway
|
Mark M. | |
Gabriele |
oh
|
Gabriele |
now it's connecting, but two times
|
Gabriele |
and not one!
|
Mar 12 | 8:10 PM |
Gabriele |
I'm reaching if (networkInfo.getType() ==
ConnectivityManager.TYPE_WIFI && networkInfo.isConnected()) {
two times and it's true two times, why?
|
Kevin M. | has left the room |
Mark M. |
I have no idea
|
Gabriele |
:O
|
Gabriele |
isn't there a way to check which is the reason of the event received?
|
Mark M. |
you can check the DetailedState of the NetworkInfo, perhaps
|
Gabriele |
it says: Details CONNECTED
|
Gabriele |
two times :O
|
Mark M. |
sorry
|
Mark M. |
I suppose when I use this, I do not care that I might get duplicate broadcasts
|
Gabriele |
my problem is that, if there are duplicates, I'm launching my service two times
|
Mar 12 | 8:15 PM |
Mark M. |
since services are singletons, you will still only have one service
|
Mark M. |
so, perhaps the service needs to be smart enough
to not do more work in onStartCommand() if it is already doing the work,
or something like that
|
Gabriele |
and how can I check it?
|
Gabriele |
anyway it seems that my s2 is giving me the broadcast only one time
|
Gabriele |
so the problem maybe is the rom of my xoom
|
Mark M. |
perhaps
|
Mark M. |
ideally, your service knows whether or not it is doing some work already (e.g., holding onto the Thread you forked)
|
Gabriele |
or maybe is due to android 4.2 (my s2 has 4.1)
|
Gabriele |
anyway I need to check if it's already working
|
Mark M. |
to be safe, I would recommend that
|
Gabriele |
so I don't have to care about it
|
Gabriele |
a static field is a bad thing?
|
Mar 12 | 8:20 PM |
Mark M. |
um, that depends on what it is and how you use it
|
Mark M. |
static data members represent possible memory leaks
|
Mark M. |
so the #1 thing is to make sure that your use of a static data member will not represent a runaway memory leak
|
Gabriele |
I meant to check if the service is already running
|
Mark M. |
the service would not need a static data member to see if it is running -- a regular data member will do
|
Mark M. |
again, services are natural singletons
|
Gabriele |
ah true
|
Gabriele |
sorry, here it's late :P
|
Gabriele |
so I can set it to true on onstartcommand and false before I finish my work
|
Mark M. |
yes, though if that work is in a background thread, you may want to use an AtomicBoolean to be safe
|
Mar 12 | 8:25 PM |
Gabriele |
thank you very much Mark, good night or good day :P
|
Mark M. |
good night!
|
Mar 12 | 8:30 PM |
Gabriele | has left the room |
Mark M. | turned off guest access |