Office Hours — Today, January 8

Friday, January 4

Jan 8
9:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
Carlos V.
has entered the room
Mark M.
hello, Carlos!
how can I help you today?
Carlos V.
Hi Mark
Marcin
has entered the room
Mark M.
hello, Marcin!
Carlos: do you have a question?
10:00 AM
Carlos V.
I'm working on a DateDialogFragment and I'm struggling to restore the state of a "set date" when the edittext field is clicked again
Ricardo P.
has entered the room
Ron B.
has entered the room
Carlos V.
I'm using onSavedInstanceState to save the day/month/year and trying to use those values in onCreateDialog
Mark M.
(BTW, hello Ricardo and Ron -- I will be with you shortly)
Ron B.
Hello Mark
Ricardo P.
Hello
Carlos V.
Once a user selects a date (my EditText has an onClick attribute) when the EditText is re-clicked the DateDialog is re-set to today's date.
Eugene
has entered the room
Carlos V.
Can't seem to find why onCreateDialog always has a null bundle
Mark M.
It will only have a non-null bundle on a configuration change or similar event, AFAIK
(BTW, howdy, Eugene -- you are fifth in line -- I will be with you as soon as I can)
Carlos V.
yeah, that's what I'm seeing.
Eugene
Hello Mark and all. Please advice what is the best way to work with sqlite on non rooted device? I need to check if my data inserts to a table(s) correctly.
Mark M.
Eugene: I will get to your question in turn
Eugene
thank you
Carlos V.
Is there a way to retain the object? Do I have to send the calendar object to the activity? I'm doing everything from the Fragment
Mark M.
Carlos: you will need to supply your initial data to your DialogFragment by some other means
Carlos V.
hmmm
Mark M.
Carlos: you are not doing "everything from the Fragment", because your EditText is not in the fragment
consider using the factory pattern and setArguments() on the Fragment to pass in initial data
Carlos V.
That's right. I guess most of it :)
Mark M.
I have not tried that with a DialogFragment, but I would imagine it would work
10:05 AM
Mark M.
so you'd have a static method on SelectDateFragment that takes a Calendar or something
Carlos V.
I've done a similar approach in a master/detail logic. I'll give that a try here. Thanks!
Mark M.
OK
I will be back with you in a little while, after I have taken a question from everyone else
Marcin: do you have a question?
Marcin
Hi Mark, yes
I have sherlock actionbar with search.
Ron B.
Hi Mark,
Marcin
I dont have searchable activity.. in onCreateOptionsMenu I add setOnSuggestionListener
then create suggestions as simplecursorAdapter
Ron B.
Sorry I was pre-typing, thought it wouldn't send :-)
Marcin
and set them with setSuggestionsAdapter
it all works fine
however.. when i start typing in search box in action bar
it doesnt matter what i type.. as soon as i enter any two characters
list of all suggestions pops up
i would like it to be filtered, depending what i type
Mark M.
I have not used SearchView, but from what I see of the API, that is not how it works
you could try using an AutoCompleteTextView of your own
since AutoCompleteTextView has the behavior that you describe
10:10 AM
Mark M.
another possibility is to register an OnQueryTextListener, and set a new CursorAdapter whenever the query text changes
I have no idea how well that works
of course, I also have no idea why setSuggestionsAdapter() needs a CursorAdapter, rather than just a regular ListAdapter
Marcin
yes.. its strange
Mark M.
hopefully, one of those two techniques will get you what you want
Marcin
thanks for suggestions Mark, thats it from me
Mark M.
OK
Ricardo: do you have a question?
Ricardo P.
yes I do
it's somewhat long question (15 lines), but easy to answer (I hope)
View paste
My question is about thread management, configuration changes, and fragments. I know that Android guarantees that when a configuration change takes place, no messages are dispatched in the UI thread until the activity gets recreated (its onCreate() method finishes). This behaviour is documented in the onRetainNonConfigurationInstance() method, and has been discussed in Stackoverflow and Google Groups.

However, in regards to fragments, I haven't been able to find such guarantees in the documentation. In The Busy Coder's Guide to Android Development, however, you say (page 380 from PDF of the last version of the guide) that such guarantee holds. In particular, you say:

"Android guarantees that, while on the main application thread, getActivity() will
return a valid Activity. Moreover, once the configuration change starts, no
messages on the message queue will be processed until after onCreate() of the
hosting activity (and onActivityCreated() of the fragment) have completed their
work."

But I haven't been able to find the "onActivityCreated()" guarantee anywhere in the docs. So my question is, where is that relevant piece of information officially documented?
Mark M.
I like easy questions :-)
hmmmm...
off the top of my head, I forget where I came up with that
hold on one moment...
Ricardo P.
ok
Mark M.
if I had to guess, I probably based it on the diagram and material here: http://developer.android.com/guide/components/f...
Ricardo P.
hmmmmm
Mark M.
my belief is that the framework will invoke onActivityCreated() after your onCreate() code has wrapped up, but before the base implementation of onCreate() returns
10:15 AM
Ricardo P.
no
I checked that yesterday
in a configuration change, onActivityCreated() is called in the activity's onStart() method
so that's why I am a little confused about this
Mark M.
it's entirely possible the book is wrong then
I will make a point to do some more investigation
Ricardo P.
ok, so thread management though fragments is still a problem if this is not necessarily true
Mark M.
well, it's more a question of what lifecycle methods have the guarantee
for example, if you replace onActivityCreated() with onCreateView() in the passage you quoted, that I am more certain is correct
Ricardo P.
well, I cheched that onAttach() is called in the activity's onCreate(), so I guess that in that case the guaranteee holds
Mark M.
right
so it's a matter of trying to determine what the current behavior is, then my trying to wrangle some confirmation of expectations out of Googlers
like I said, I'll need to do some more investigation
my apologies for possibly steering you down the wrong path with what's in there now
Ricardo P.
ok, that would be wonderful, since this is a very important part of the framework and there is obviously not much documentation out there
no worries
thanks a lot
I am done!: )
Mark M.
Ron: your turn!
Ricardo P.
has left the room
Ron B.
Hi Mark, Hopefully another long liner, but easy. I'm using Tabhost/Tabwidget to support Android 2.x devices. I have the following code;
View paste (4 more lines)



TabHost tabs=(TabHost)findViewById(R.id.tabhost);
        tabs.setup();
        // login tag
        TabHost.TabSpec login=tabs.newTabSpec("tag1");
        login.setContent(new Intent(this, Login.class));
        login.setIndicator("Login/Logout",getResources().getDrawable(android.R.drawable.ic_dialog_info));
        tabs.addTab(login);

When executing the addTab line I get the following exception:

01-08 09:31:01.903: E/AndroidRuntime(1426): Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
01-08 09:31:01.903: E/AndroidRuntime(1426): 	at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:655)
...
10:20 AM
Mark M.
that's odd
oh, wait
hold on one moment...
there are two setup() methods
the one you are calling works if your tab contents are views
the one the error message wants you to call takes a LocalActivityManager as a second parameter, and is needed if you have activities in tabs
Ron B.
Thought it was something like that, per the example in your book...
Mark M.
(which, BTW, has been deprecated for nearly two years)
if you use TabActivity, you do not need the setup() call, as it does that for you
assuming your activity that hosts this TabHost is really an ActivityGroup, call setup(this)
Ron B.
I thought is was just the TabActivity that was deprecated. Is there a better was to support Android 2.x?
Mark M.
it's more that ActivityGroup, and activities-in-activities, that was deprecated
just about any other tab solution works on 2.x: views in a TabHost, action bar tabs, ViewPager with PagerTabStrip, ...
let me take questions from the others, and I will be back with you in a few minutes
Eugene: copy your database to external storage, and examine it there
10:25 AM
Eugene
I've just connected to db using adb (on emulator), but it happened I don't have my talbe in there... .tables gives me nothing, don't you know why it could be?
Carlos V.
Mark, I have one more question regarding DialogFragments. Let me know when its my turn again.
Mark M.
Eugene: bear in mind that the sqlite3 command will quietly create an empty database if it cannot find one on the path that you specified
so, first, make sure that you gave it the proper path to your database on the emulator
Eugene
oh, ok, thanks
Mark M.
or, copy off the emulator (File Explorer or adb pull) and examine it using a desktop SQLite tool, like the Firefox extension that I use
another approach would be to add test methods to your unit test suite that inspect the contents of the database
Eugene
got it, thank you
Mark M.
Carlos: do you have another question?
10:30 AM
Carlos V.
Yes. I read in the book about how the DateDialogFragment no longer has a cancel button.
Mark M.
there is no DateDialogFragment in Android
do you mean DatePickerDialog?
Carlos V.
I use this app called "Tasks" that does show it, even on my phone with Android 4.2.
Oopps...meant DialogFragment for DatePicker :)
Mark M.
you need to add a negative button listener
Carlos V.
I read this long post on stackoverflow about a work around for pressing the back button when the user wants to get out of the Dialog.
Mark M.
yes, I linked to that from the book
Carlos V.
Does the negative button listener automatically adds the cancel button or do I have to extend the class?
Mark M.
AFAIK, the negative button listener alone suffices
bear in mind that you can also either fork DatePickerDialog, or create your own AlertDialog with a DatePicker, so you have complete direct control
Marcin: do you have another question?
Carlos V.
Yes, I was thinking of using AlertDialog and doing that. I guess using AlertDialog is a little extra work but on the upside it is more "future proof".
Mark M.
Carlos: agreed
10:35 AM
Carlos V.
BTW, do you have a bitbucket account? Just wondering in case in a future chat I need to show you a private source file? Just wondering.
Mark M.
no, I don't use bitbucket
I'm a GitHub guy
Ron: do you have another question?
Ron B.
Thanks Mark, I stuck with TabHost/Tabwidget based on page 162 of Advanced Android:
Carlos V.
Hehehe. Fair enough. I use bitbucket solely because it has free private repos :) Thanks again for your feedback on my questions. That is all for today!
Ron B.
View paste
In Android 1.x and 2.x, if you wanted tabs, you usually trotted out TabHost
and TabWidget.
On Android 3.x, that is being replaced by tabs managed in the action bar.
I just tried ActionBar, it's not recognized in 2.x?
Mark M.
Note that _The Busy Coder's Guide to Advanced Android Development_ was retired a while ago, replaced by the omnibus _The Busy Coder's Guide to Android Development_
to use the action bar on Android 2.x, you need a backport, like ActionBarSherlock
ActionBarSherlock is covered heavily in the omnibus
so, in Version 4.5, the action bar (with ActionBarSherlock) is covered in "Options Menus and the Action Bar", and action bar tabs is covered in "Action Bar Navigation"
Ron B.
Hmmm, or I can just add the LocalActivityManager parm to the addTab method call?
10:40 AM
Mark M.
if you mean the setup() call, yes
Ron B.
So it's setup(LocalActivityManager ??)
Mark M.
yes
or http://goo.gl/L2sqh since that link did not work well
Ron B.
OK, thanks!
Mark M.
Eugene: do you have another question?
OK, if anyone has any questions, chime in
10:45 AM
Ron B.
has left the room
10:50 AM
Marcin
has left the room
Eugene
has left the room
Carlos V.
has left the room
10:55 AM
Mark M.
turned off guest access

Friday, January 4

 

Office Hours

People in this transcript

  • Carlos Vega
  • Eugene
  • Marcin
  • Mark Murphy
  • Ricardo Palma
  • Ron Bruckman