Office Hours — Today, November 6

Yesterday, November 5

Nov 6
9:50 AM
Mark M.
has entered the room
9:55 AM
Mark M.
turned on guest access
bsr
has entered the room
bsr
Good morning Mark
10:00 AM
Mark M.
howdy, bsr!
10:00 AM
Mark M.
how can I help you today?
bsr
I was playing with Dynamic fragments, and Rotation Fragment demo crashes
View paste
11-06 07:22:40.967: ERROR/EmbeddedLogger(1589): Error getting package label: com.android.htccontacts
        java.lang.NullPointerException
        at com.htc.embedded.EmbeddedLogger.onHandleApplicationCrash(EmbeddedLogger.java:56)
        at com.android.server.am.ActivityManagerService.handleApplicationCrash(ActivityManagerService.java:7355)
        at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:1045)
        at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1672)
        at android.os.Binder.execTransact(Binder.java:339)
        at dalvik.system.NativeStart.run(Native Method)
11-06 07:22:40.967: ERROR/EmbeddedLogger(1589): Application Label: <ERROR>
11-06 07:22:40.967: WARN/ActivityManager(1589): Force finishing activity com.android.htccontacts/.MultipleActivitiesMain
11-06 07:22:40.977: WARN/ActivityManager(1589): Force finishing activity com.commonsware.android.rotation.frag/.RotationFragmentDemo
I was mainly looking to see how you retain the view on rotation
Mark M.
I have nothing to do with com.android.htccontacts
bsr
ok, I use htc device
Mark M.
try running the sample on an emulator
bsr
ok, anyway, I could capure the state of fragment in a private variable, but the view lose its contents.
I saw a blog post just now about this
do you have an example in the book how best I can re-initialize view after config change
in case of dynamic fragments
Mark M.
I am not a big fan of the technique used in that blog post, except if there is no alternative (e.g., a WebView)
bsr
oh. What should be a better approach
Mark M.
hold onto the data, not the views
bsr
ok, then reinitialize in onCreateView?
Mark M.
that's a likely spot
10:05 AM
bsr
One more quick qn,
I was following the tutorial on REST client through Intent + ResultReceiver
The author initialize mReceiver in fragment constructor
View paste
// We are going to use a constructor here to make our ResultReceiver,
    // but be careful because Fragments are required to have only zero-arg
    // constructors. Normally you don't want to use constructors at all
    // with Fragments.
    public RESTResponderFragment() {
        mReceiver = new ResultReceiver(new Handler()) {
I wonder the rational, rather than doing it in onCreate
Mark M.
you would have to ask the author
bsr
Do you think, it will be properly initialized if I do it in onCreate
I don't fully know the lifecycle
Mark M.
presumably, yes
bsr
:-) .. that's it.. thanks a lot
Mark M.
you are very welcome
bsr
have a great day.
bsr
has left the room
Mark M.
you too!
10:15 AM
soli
has entered the room
Mark M.
howdy, soli!
how can I help you today?
soli
Hi mark!
View paste
I have a pager which uses a FragmentPagerAdapter to switch between 5 gridviews.
Each of these gridviews loads pictures(Uri's) from the same DB table, but with a different whereclause.
does calling a new cursor and adapter on onCreateView is efficient?
View paste
Cursor photosCursor = ((DemoActivity)getActivity()).db.getReadableDatabase().rawQuery("SELECT _id, uri, category "
                + "FROM photos ORDER BY uri Where category=" + position,
            null);
	    
	    PhotosAdapter photosAdapter = new PhotosAdapter(getActivity(), photosCursor);
Mark M.
well, I do not see that you have a choice except to create a new Cursor and Adapter
hence, whether it is efficient or not does not matter -- all that matters is whether it is fast enough for your needs
soli
can i create them elsewhere? like on new instance ?
oh ok
Mark M.
I fail to see how that will help
soli
ok, well thanks:)
Mark M.
now, you really should be doing that database query on a background thread
such as via an AsyncTask
you will be getting some nasty messages from StrictMode if you have that enabled
10:20 AM
soli
just haven't got around to it
:)
Mark M.
oh, OK
soli
oh another thing i wanted to ask is if you are available for questions through emails(with a fee of course)
Mark M.
feel free to ask other questions, if you have them -- the chat room is not very crowded right now... :-)
soli
yeah hehe:)
Mark M.
yes, I do a bit of online question-and-answer consulting via email, but not that much
feel free to contact me off-chat at mmurphy@commonsware.com
to discuss what you need
soli
ok great, i will. It would help me a lot. Have a good day!
Mark M.
you too!
10:35 AM
bsr
has entered the room
bsr
Mark, one more quick qn
Mark M.
hello again!
bsr
Can I mix static and dynamic fragments
View paste (5 more lines)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="horizontal" >

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                 android:id="@+id/fragment_list_container"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent" />
    <fragment
            android:id="@+id/detailFragment"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="match_parent"
...
I dynamically add the fragment_list_container
but, the details fragment is static (through xml)
is it a possibility
or should it be dynamic too
Mark M.
what do you mean by "dynamically add the fragment_list_container"?
bsr
through FragmentManager
at runtime
Mark M.
are you saying that the layout you have pasted above is itself a fragment, containing another fragment?
because FragmentManager works with Fragments, not layouts
bsr
no, this is main.xml
View paste
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        if (getFragmentManager().findFragmentById(R.id.fragment_list_container) == null) {
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.add(R.id.fragment_list_container, new ListFragment());
            ft.commit();
        }
this is my activity
10:40 AM
Mark M.
I have never tried that
bsr
sorry, I am bit lousy with terminology
Mark M.
I think that you will lose track of your static fragment
bsr
ok, that may be the problem as it is not dispaying
Mark M.
and that the ListFragment will float over top of the static fragment on the Z axis
soli
has left the room
Mark M.
which is probably not what you want
bsr
oh ok
Mark M.
and AFAIK you cannot use a FragmentTransaction to manipulate a static fragment (e.g., replace() or remove() it)
bsr
ok
I may better use one or other (static / dynamic) and not to mix then
Thanks Mark. THat's it
Mark M.
that would be my recommendation
bsr
catch u later, have a great day
bsr
has left the room
11:00 AM
Mark M.
turned off guest access

Yesterday, November 5

 

Office Hours

People in this transcript

  • bsr
  • Mark Murphy
  • soli