Office Hours — Today, January 10

Tuesday, January 8

Jan 10
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Marcin
has entered the room
Mark M.
howdy, Marcin!
how can I help you today?
Marcin
Hi Mark
I have a no UI Activity with Loader.
Mark M.
by "no UI Activity", do you mean Theme.NoDisplay?
Aaron
has entered the room
Mark M.
(BTW, hi, Aaron -- I will be with you shortly!)
Marcin
To be more precise I have actionbar with two tabs
4:00 PM
Aaron
Hello. Sounds good
Marcin
and my activity basically just setups fragments with listviews for both
tabs
then Loader runs after a button is pressed in actionbar and when it is finished it refreshes fragment with a listview in Tab A.
when loader is finished, Activity has a listener to it which finds listview fragment
and forces its list to reload.. it happens like this
View paste
Fragment mlf = getSupportFragmentManager().findFragmentById( android. R. id. content);
            if (mlf != null) {                 
                 mlf.getLoaderManager().getLoader( 0).forceLoad();
            }
Mark M.
that doesn't force the list to reload -- it forces the Loader to reload
Marcin
it all works fine
true
EGHDK
has entered the room
Marcin
the problem appears when i rotate the device
mlf can not be found
Mark M.
(BTW, howdy, EGHDK -- be with you in a few minutes)
Marcin
i can see that the initial loader (started from actionbar button) works properly
Mark M.
are you sure that you are not removing that fragment somewhere?
Marcin
in my onCreate Activity
i have
if(savedInstance == null){..}
and then
View paste
	ActionBar actionBar = getSupportActionBar();
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		actionBar.setDisplayShowTitleEnabled(false);
		Tab tab = actionBar.newTab().setText(R.string.tab_merchants)
				.setTabListener(new TabListener<MerchantsListFragment>(this, "merchant", MerchantsListFragment.class));
		actionBar.addTab(tab);

		tab = actionBar.newTab().setText(R.string.tab_deals)
				.setTabListener(new TabListener<DealsListFragment>(this, "deal", DealsListFragment.class));
		actionBar.addTab(tab);
4:05 PM
Marcin
so that this piece of code always fires (also on orientation change)
my on tab selected is typical
View paste (2 more lines)
public void onTabSelected(Tab tab, FragmentTransaction ft) {
			Log.d(TAG, "onTabSelected");

			mFragment = mActivity.getSupportFragmentManager().findFragmentByTag(mTag);

			if (mFragment == null) {
				Log.d(TAG, "mFragment is null");
				// If not, instantiate and add it to the activity
				mFragment = Fragment.instantiate(mActivity, mClass.getName());
				ft.add(android.R.id.content, mFragment, mTag);
			} else {
				Log.d(TAG, "mFragment is not null");
				// If it exists, simply attach it in order to show it
				ft.attach(mFragment);
			}
...
Mark M.
first, if getSupportFragmentManager().findFragmentById( android. R. id. content); is returning null, then either you never selected a tab, or somewhere you are removing/detaching the fragment from the tab
second, the code you are executing there does not need the fragment anyway, since fragments use the activity's LoaderManager
just get rid of the mlf. and do getLoaderManager().getLoader(0).forceLoad();, if you are sure that is the code that should be executed in this condition
let me take questions from the others, and I will be back with you in a bit
Aaron: do you have a question?
Marcin
thanks for suggestions Mark, will run some quick tests
4:10 PM
Mark M.
OK, Aaron, if you return, chime in
EGHDK: do you have a question?
EGHDK
Hmm... I will go ahead and ask mine.
Yep.
I have compiled a nice little list of "small" questions.
Aaron
go for it.. Ill jump in next. I only really have 1 question right now.
Mark M.
EGHDK: go ahead with the first one
EGHDK
My first "problem" is that I finish my main_activity (my only activity). But when I press the "recent apps" button/multitasking button, I see the picture of that activity
Mark M.
of course
EGHDK
And if I click that little icon, it still comes up to that screen.
Mark M.
yup, that's perfectly normal
Aaron
Hey Mark. I have been working with maps v2. I have been working out all my problems before i put together a full project. In one of my test programs i wanted to test the use of supportmapfragments. I created a project that added 2 fragments to a container and hides one of them. I put 2 different markers on each map to make sure i knew which one was showing.
woops sry didnt mean to press enter.
4:15 PM
EGHDK
So I can write `this.finish();` and the application will close, but I can still open it up. So does it ever actually finish()?
Mark M.
it finished when you called finish()
and then another copy was created when the user tapped the entry in the recents list
and that one will finish when the user presses BACK or you call finish()
and if the user taps the entry in recents again, yet another copy will be created
ad nauseum
EGHDK
Any way to "stop" that?
Mark M.
stop what?
if the user launches your app, they would like it to launch
EGHDK
But it launches to something that shouldn't be there.
Mark M.
that statement makes no sense
EGHDK
Hahaha.
Okay, let me rephrase this whole thing.
What I really want it to do, it when they click the app, I don't want it to start at that specific spot of the application.
4:20 PM
EGHDK
I would like for them to get redirected to the home screen of the application.
Mark M.
first, why?
EGHDK
Even though that doesn't make sense for 99% of apps, it seems practical in my application.
Aaron
can i save the quote?
that quote.
Mark M.
EGHDK: you can try playing around with stuff like android:finishOnTaskLaunch or something to change this behavior, but I do not have a solid recipe for it
let me take questions from the others, and I'll be back with you shortly
Aaron
ok :) yay
Mark M.
Aaron: OK, I've read what you posted above... please continue
Aaron
View paste
I hooked up a button to show the second fragment and hide the first.

Problem: When i click the button to show the second mapfragment it will not show up but i lose control the the first fragment(cant move map, cant zoom). I am not sure what is going on here or if i am just missing something stupid again. I feel like the fragment is switching but the view is not refreshing.
Mark M.
um, I haven't the foggiest notion what might be going on
if you can create a sample project that reproduces the error, I can try looking at it
IIRC, you posted a StackOverflow question on this -- right?
Aaron
ya
I have been able to use replace.
4:25 PM
Aaron
but that defeats the purpose of loading in the mapfragments
Mark M.
what do you mean "that defeats the purpose..."?
Aaron
Interesting.
David O.
has entered the room
EGHDK
Hey Mark, regarding "android:clearTaskOnLaunch" would that be set on the mainActivity or on the Activity that I do not want anyone to get to once it finishes().
David O.
Hello
Mark M.
for example, if you use ViewPager, it will do add() and remove()
(David: hi! I will be with you shortly)
David O.
Thank you
Aaron
ya i was working with your book example and saw the viewpager .
Mark M.
(EGHDK: from the docs, I'd say your home activity would have this flag)
Aaron
I was thinking of using it for the map views but i dont need the swiping.
Mark M.
my point is that add()/remove()/replace() should not intrinsically be a problem
since that's the stuff that FragmentPagerAdapter and such use
so I am trying to understand why this "defeats the purpose"
Aaron
OK. I will just revert to replace. Crazy issue though. I am glad that it is not some trivial stupid thing that i am missing.
since it works.
Thankyou good sir.
EGHDK
Just chiming in here. I hate fragments, I had the biggest issues with remove(). It never seemed to work. Then I just started using hide() and everything was peachy.
Mark M.
they may be using SurfaceView, which has... odd effects when there are multiple of them floating around
David: your turn! do you have a question?
David O.
I have a few questions actually, but they are short
Mark M.
shoot me your first one
David O.
first question: is there a broadcast reciever to listen for changes in network states?
4:30 PM
David O.
e.g. going from an unconnected state to a connected one?
Aaron
EGHDK I actually tried using hide() it doesnt work with map fragments.
Mark M.
David: see ConnectivityManager
David O.
thanks
Mark M.
since that was really quick, fire me your next one
David O.
is the latest version of actionbar sherlock compatible with the latest support library?
Mark M.
AFAIK, yes
David O.
i saw on stack overflow that you have something on github
using both
Mark M.
leastways, I am running with that combination and haven't run into a problem
David O.
It was in response to a question about embedding fragments
Mark M.
pretty much all the samples that use ActionBarSherlock are using the latest Android Support package JAR
again, I haven't run into any issues
David O.
so i shouldn't have to add the v17 support library seperately?
ok thank you
Mark M.
v17?
Aaron
v4 or v13 i though
t
Mark M.
there is no v17
there is v4 and v13 as JARs
David O.
i mean v4
Mark M.
plus a v7 that's actually an Android library project (for GridLayout)
David O.
i want to be able to use getChildFragment manager
Mark M.
any project using ActionBarSherlock needs an Android Support package v4 JAR
you are welcome to use the latest if you wish
David O.
thank you
EGHDK
Oh that reminds me. My second question to Mark. On SO a very long time ago. Probably around 8+ months, I was completely new to android, and I said that it was stupid that they do not automatically include the support library. You stated that (If I remember correctly) that not everyone needed to support all the older versions, so they do not include it automatically. Have they changed that? I'm pretty sure every app I start, has the compat jar.
Mark M.
Marcin: do you have another question
Marcin
yes
its actually continuing on the first one
Mark M.
(EGHDK: that's a matter of the particular activity wizard you chose)
Marcin
to add to your comments
4:35 PM
Aaron
Every time i use ABS i have to include the latest ABS and remove support lib v4 from my libs folder.
Marcin
to your first comment : onTabSelected fires before "code looking for mlf"
to your second comment : from my test it seems that fragment loaders are different than activity loaders
Mark M.
it's possible that a config change fires onTabUnselected(), though
Marcin
it does not appear in lofs
logs
Mark M.
since you are using add() in onTabSelected(), I presume you are doing remove() in onTabUnselected()
Marcin
View paste
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
			Log.d(TAG, "onTabUnselected");
			if (mFragment != null) {
				// Detach the fragment, because another one is being attached
				ft.detach(mFragment);
			}
		}
Aaron
Have a good day everyone. Good Lunk in your projects. And Thankyou Mark.
Mark M.
Marcin: I cannot explain the behavior that you are seeing and have no good way really of assisting you
Aaron
has left the room
Marcin
ok, can I have another question then?
Mark M.
sure
Marcin
How would you implement 3tabs with actionbar navigation? each tab having a separate backstack of fragments
Mark M.
personally, I am not a fan of tabs having distinct back stacks
4:40 PM
Mark M.
that being said, you'd have to manage all of that yourself
as Android only manages a back stack on an activity basis, not a per-tab basis
Marcin
what is the proper ux then here? any apps that you could point to in market as examples?
Mark M.
for an activity with tabs, BACK exits the activity
as is done by probably 99% of apps on the market that use tabs in any form
the only *exception* is in the case of a browser with visible tabs, where BACK is overridden to have meaning within the app
and they aren't using a fragment back stack for that, unless I miss my guess
Marcin
ok.. will have to think about it harder
thanks
Mark M.
EGHDK: do you have another question?
Marcin
regarding your second comment on my first question
View paste
public LoaderManager getLoaderManager ()

Added in API level 11
Return the LoaderManager for this fragment, creating it if needed.
from docs
Mark M.
(Marcin: and if you look at the source code, it gets that from the activity)
Marcin
maybe :) but mlf.getLoadermanager.getL and simple getLoaderManager.getL run different loaders
first from fragment, second from activity
Mark M.
David: do you have another question?
4:45 PM
David O.
yes...another general question
is it safe to use two annotation libraries?
Mark M.
um, I have no idea
I would assume so
David O.
I would like to use ORMLite and GSON annotation library
Mark M.
after all, Android has its annotations, and third party JARs might add their own, and I haven't heard about Android's annotations breaking all those others
if they have name collisions there could be issues
David O.
thank you
Mark M.
EGHDK: do you have another question?
EGHDK
Yes,
In reference to the support library again.
When I'm writing some application, how do I know if the support library should be used or not?
I had an example but forgot. heh.
Mark M.
if you are trying to use an android.support.v4 class, directly or indirectly (e.g., via ActionBarSherlock), you need the v4 JAR
if you are trying to use an android.support.v13 class, you need the v13 JAR
EGHDK
Oh. Like notificationcompat.
Mark M.
right
EGHDK
I remember doing a whole bunch of notification stuff, and then found out about notificationCompat
Mark M.
in fact, most if not all of the ...Compat classes are in the the android.support.v4 package
Marcin: do you have another question?
EGHDK
But, I'm just saying, how was I supposed to know about notificationCompat
Reading the documentation I guess?
Mark M.
or books written by balding guys :-)
EGHDK
Touche
4:50 PM
David O.
lol
EGHDK
I was just hoping android would be like (Hey! Maybe you wanna use the support compat instead!)
But there's nothing like that, that exists huh?
Marcin
question ab tabs
Mark M.
occasionally they have notes like that, but usually only for stuff they officially deprecated
Marcin: go ahead
Marcin
if i have two tabs A,B... both have two listviews
my normal thinking would be that when i click an item
EGHDK
So what would you say are the top three compat imports that people end up using?
Marcin
switch etc etc it behaves like browser
so without ability of each tab having a backstack
is the proper behaviour that clicking any tab, clears all fragments and presents the listview?
Mark M.
that's impossible to answer in the abstract
Marcin
simple list
click item, shows merchant, click item shows detail
same for other tab but deals
Mark M.
on a phone-sized screen, launch another activity
4:55 PM
Marcin
for merchant view?
Mark M.
on a tablet-sized screen, reconsider having the tabs in the first place, going with the master-detail pattern instead
for whatever the list item click needs to show
Marcin
any links to this master-detail pattern?
or snippets maybe
Mark M.
it's all over the docs, and in the book (in the large-screens chapter and the last tutorial)
Marcin
gr8, thanks for hint
EGHDK
Yeah, master-detail pattern sounds scary, but is really easy. I'm terrible at all this stuff, and I'm able to do it.
hahaha
Mark M.
EGHDK: I have no idea what "the top three compat imports" are, sorry
Aaron: do you have another question?
EGHDK
Mark Murphy. Any opinion?
notifCompat. ActionBarCompat.
theres a fragmentCompat too right?
Mark M.
not by name, but the Android Support package has a backport of fragments
Aaron: do you have another (quick) question?
whoops, I meant David
David: do you have another (quick) question?
David O.
no problem
5:00 PM
David O.
i had something...and i forgot it
Mark M.
OK
EGHDK
See ya mark. I'll be back to bother you on Tuesday.
David O.
well...i guess it will have to wait till tuesday
Mark M.
that's a wrap for today's chat
Marcin
thanks Mark, bye
Mark M.
the transcript will be archived at http://commonsware.com/office-hours/ shortly
David O.
thanks, goodbye
Mark M.
next chat is Tuesday, 7:30pm Eastern
have a pleasant day, all!
Marcin
has left the room
EGHDK
has left the room
David O.
has left the room
Mark M.
turned off guest access

Tuesday, January 8

 

Office Hours

People in this transcript

  • Aaron
  • David Ozersky
  • EGHDK
  • Marcin
  • Mark Murphy