FragmentActivity.java revision 8205f0588fe605821216e4b9fe2c26709c4db8be
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.v4.app;
18
19import android.app.Activity;
20import android.content.Context;
21import android.content.Intent;
22import android.content.res.Configuration;
23import android.content.res.TypedArray;
24import android.os.Bundle;
25import android.os.Handler;
26import android.os.Message;
27import android.os.Parcelable;
28import android.util.AttributeSet;
29import android.util.Log;
30import android.view.KeyEvent;
31import android.view.Menu;
32import android.view.MenuItem;
33import android.view.View;
34import android.view.Window;
35
36import java.io.FileDescriptor;
37import java.io.PrintWriter;
38import java.util.ArrayList;
39import java.util.HashMap;
40
41/**
42 * Base class for activities that want to use the support-based
43 * {@link android.support.v4.app.Fragment} and
44 * {@link android.support.v4.content.Loader} APIs.
45 *
46 * <p>When using this class as opposed to new platform's built-in fragment
47 * and loader support, you must use the {@link #getSupportFragmentManager()}
48 * and {@link #getSupportLoaderManager()} methods respectively to access
49 * those features.
50 *
51 * <p>Known limitations:</p>
52 * <ul>
53 * <li> <p>When using the &lt;fragment> tag, this implementation can not
54 * use the parent view's ID as the new fragment's ID.  You must explicitly
55 * specify an ID (or tag) in the &lt;fragment>.</p>
56 * <li> <p>Prior to Honeycomb (3.0), an activity's state was saved before pausing.
57 * Fragments are a significant amount of new state, and dynamic enough that one
58 * often wants them to change between pausing and stopping.  These classes
59 * throw an exception if you try to change the fragment state after it has been
60 * saved, to avoid accidental loss of UI state.  However this is too restrictive
61 * prior to Honeycomb, where the state is saved before pausing.  To address this,
62 * when running on platforms prior to Honeycomb an exception will not be thrown
63 * if you change fragments between the state save and the activity being stopped.
64 * This means that in some cases if the activity is restored from its last saved
65 * state, this may be a snapshot slightly before what the user last saw.</p>
66 * </ul>
67 */
68public class FragmentActivity extends Activity {
69    private static final String TAG = "FragmentActivity";
70
71    private static final String FRAGMENTS_TAG = "android:support:fragments";
72
73    // This is the SDK API version of Honeycomb (3.0).
74    private static final int HONEYCOMB = 11;
75
76    static final int MSG_REALLY_STOPPED = 1;
77    static final int MSG_RESUME_PENDING = 2;
78
79    final Handler mHandler = new Handler() {
80        @Override
81        public void handleMessage(Message msg) {
82            switch (msg.what) {
83                case MSG_REALLY_STOPPED:
84                    if (mStopped) {
85                        doReallyStop(false);
86                    }
87                    break;
88                case MSG_RESUME_PENDING:
89                    mFragments.dispatchResume();
90                    mFragments.execPendingActions();
91                    break;
92                default:
93                    super.handleMessage(msg);
94            }
95        }
96
97    };
98    final FragmentManagerImpl mFragments = new FragmentManagerImpl();
99
100    boolean mCreated;
101    boolean mResumed;
102    boolean mStopped;
103    boolean mReallyStopped;
104    boolean mRetaining;
105
106    boolean mOptionsMenuInvalidated;
107
108    boolean mCheckedForLoaderManager;
109    boolean mLoadersStarted;
110    HCSparseArray<LoaderManagerImpl> mAllLoaderManagers;
111    LoaderManagerImpl mLoaderManager;
112
113    static final class NonConfigurationInstances {
114        Object activity;
115        Object custom;
116        HashMap<String, Object> children;
117        ArrayList<Fragment> fragments;
118        HCSparseArray<LoaderManagerImpl> loaders;
119    }
120
121    static class FragmentTag {
122        public static final int[] Fragment = {
123            0x01010003, 0x010100d0, 0x010100d1
124        };
125        public static final int Fragment_id = 1;
126        public static final int Fragment_name = 0;
127        public static final int Fragment_tag = 2;
128    }
129
130    // ------------------------------------------------------------------------
131    // HOOKS INTO ACTIVITY
132    // ------------------------------------------------------------------------
133
134    /**
135     * Dispatch incoming result to the correct fragment.
136     */
137    @Override
138    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
139        int index = requestCode>>16;
140        if (index != 0) {
141            index--;
142            if (mFragments.mActive == null || index < 0 || index >= mFragments.mActive.size()) {
143                Log.w(TAG, "Activity result fragment index out of range: 0x"
144                        + Integer.toHexString(requestCode));
145                return;
146            }
147            Fragment frag = mFragments.mActive.get(index);
148            if (frag == null) {
149                Log.w(TAG, "Activity result no fragment exists for index: 0x"
150                        + Integer.toHexString(requestCode));
151            } else {
152                frag.onActivityResult(requestCode&0xffff, resultCode, data);
153            }
154            return;
155        }
156
157        super.onActivityResult(requestCode, resultCode, data);
158    }
159
160    /**
161     * Take care of popping the fragment back stack or finishing the activity
162     * as appropriate.
163     */
164    public void onBackPressed() {
165        if (!mFragments.popBackStackImmediate()) {
166            finish();
167        }
168    }
169
170    /**
171     * Dispatch configuration change to all fragments.
172     */
173    @Override
174    public void onConfigurationChanged(Configuration newConfig) {
175        super.onConfigurationChanged(newConfig);
176        mFragments.dispatchConfigurationChanged(newConfig);
177    }
178
179    /**
180     * Perform initialization of all fragments and loaders.
181     */
182    @Override
183    protected void onCreate(Bundle savedInstanceState) {
184        mFragments.attachActivity(this);
185        // Old versions of the platform didn't do this!
186        if (getLayoutInflater().getFactory() == null) {
187            getLayoutInflater().setFactory(this);
188        }
189
190        super.onCreate(savedInstanceState);
191
192        NonConfigurationInstances nc = (NonConfigurationInstances)
193                getLastNonConfigurationInstance();
194        if (nc != null) {
195            mAllLoaderManagers = nc.loaders;
196        }
197        if (savedInstanceState != null) {
198            Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG);
199            mFragments.restoreAllState(p, nc != null ? nc.fragments : null);
200        }
201        mFragments.dispatchCreate();
202    }
203
204    /**
205     * Dispatch to Fragment.onCreateOptionsMenu().
206     */
207    @Override
208    public boolean onCreatePanelMenu(int featureId, Menu menu) {
209        if (featureId == Window.FEATURE_OPTIONS_PANEL) {
210            boolean show = super.onCreatePanelMenu(featureId, menu);
211            show |= mFragments.dispatchCreateOptionsMenu(menu, getMenuInflater());
212            if (android.os.Build.VERSION.SDK_INT >= HONEYCOMB) {
213                return show;
214            }
215            // Prior to Honeycomb, the framework can't invalidate the options
216            // menu, so we must always say we have one in case the app later
217            // invalidates it and needs to have it shown.
218            return true;
219        }
220        return super.onCreatePanelMenu(featureId, menu);
221    }
222
223    /**
224     * Add support for inflating the &lt;fragment> tag.
225     */
226    @Override
227    public View onCreateView(String name, Context context, AttributeSet attrs) {
228        if (!"fragment".equals(name)) {
229            return super.onCreateView(name, context, attrs);
230        }
231
232        String fname = attrs.getAttributeValue(null, "class");
233        TypedArray a =  context.obtainStyledAttributes(attrs, FragmentTag.Fragment);
234        if (fname == null) {
235            fname = a.getString(FragmentTag.Fragment_name);
236        }
237        int id = a.getResourceId(FragmentTag.Fragment_id, View.NO_ID);
238        String tag = a.getString(FragmentTag.Fragment_tag);
239        a.recycle();
240
241        View parent = null; // NOTE: no way to get parent pre-Honeycomb.
242        int containerId = parent != null ? parent.getId() : 0;
243        if (containerId == View.NO_ID && id == View.NO_ID && tag == null) {
244            throw new IllegalArgumentException(attrs.getPositionDescription()
245                    + ": Must specify unique android:id, android:tag, or have a parent with an id for " + fname);
246        }
247
248        // If we restored from a previous state, we may already have
249        // instantiated this fragment from the state and should use
250        // that instance instead of making a new one.
251        Fragment fragment = id != View.NO_ID ? mFragments.findFragmentById(id) : null;
252        if (fragment == null && tag != null) {
253            fragment = mFragments.findFragmentByTag(tag);
254        }
255        if (fragment == null && containerId != View.NO_ID) {
256            fragment = mFragments.findFragmentById(containerId);
257        }
258
259        if (FragmentManagerImpl.DEBUG) Log.v(TAG, "onCreateView: id=0x"
260                + Integer.toHexString(id) + " fname=" + fname
261                + " existing=" + fragment);
262        if (fragment == null) {
263            fragment = Fragment.instantiate(this, fname);
264            fragment.mFromLayout = true;
265            fragment.mFragmentId = id != 0 ? id : containerId;
266            fragment.mContainerId = containerId;
267            fragment.mTag = tag;
268            fragment.mInLayout = true;
269            fragment.mFragmentManager = mFragments;
270            fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
271            mFragments.addFragment(fragment, true);
272
273        } else if (fragment.mInLayout) {
274            // A fragment already exists and it is not one we restored from
275            // previous state.
276            throw new IllegalArgumentException(attrs.getPositionDescription()
277                    + ": Duplicate id 0x" + Integer.toHexString(id)
278                    + ", tag " + tag + ", or parent id 0x" + Integer.toHexString(containerId)
279                    + " with another fragment for " + fname);
280        } else {
281            // This fragment was retained from a previous instance; get it
282            // going now.
283            fragment.mInLayout = true;
284            // If this fragment is newly instantiated (either right now, or
285            // from last saved state), then give it the attributes to
286            // initialize itself.
287            if (!fragment.mRetaining) {
288                fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
289            }
290            mFragments.moveToState(fragment);
291        }
292
293        if (fragment.mView == null) {
294            throw new IllegalStateException("Fragment " + fname
295                    + " did not create a view.");
296        }
297        if (id != 0) {
298            fragment.mView.setId(id);
299        }
300        if (fragment.mView.getTag() == null) {
301            fragment.mView.setTag(tag);
302        }
303        return fragment.mView;
304    }
305
306    /**
307     * Destroy all fragments and loaders.
308     */
309    @Override
310    protected void onDestroy() {
311        super.onDestroy();
312
313        doReallyStop(false);
314
315        mFragments.dispatchDestroy();
316        if (mLoaderManager != null) {
317            mLoaderManager.doDestroy();
318        }
319    }
320
321    /**
322     * Take care of calling onBackPressed() for pre-Eclair platforms.
323     */
324    @Override
325    public boolean onKeyDown(int keyCode, KeyEvent event) {
326        if (android.os.Build.VERSION.SDK_INT < 5 /* ECLAIR */
327                && keyCode == KeyEvent.KEYCODE_BACK
328                && event.getRepeatCount() == 0) {
329            // Take care of calling this method on earlier versions of
330            // the platform where it doesn't exist.
331            onBackPressed();
332            return true;
333        }
334
335        return super.onKeyDown(keyCode, event);
336    }
337
338    /**
339     * Dispatch onLowMemory() to all fragments.
340     */
341    @Override
342    public void onLowMemory() {
343        super.onLowMemory();
344        mFragments.dispatchLowMemory();
345    }
346
347    /**
348     * Dispatch context and options menu to fragments.
349     */
350    @Override
351    public boolean onMenuItemSelected(int featureId, MenuItem item) {
352        if (super.onMenuItemSelected(featureId, item)) {
353            return true;
354        }
355
356        switch (featureId) {
357            case Window.FEATURE_OPTIONS_PANEL:
358                return mFragments.dispatchOptionsItemSelected(item);
359
360            case Window.FEATURE_CONTEXT_MENU:
361                return mFragments.dispatchContextItemSelected(item);
362
363            default:
364                return false;
365        }
366    }
367
368    /**
369     * Call onOptionsMenuClosed() on fragments.
370     */
371    @Override
372    public void onPanelClosed(int featureId, Menu menu) {
373        switch (featureId) {
374            case Window.FEATURE_OPTIONS_PANEL:
375                mFragments.dispatchOptionsMenuClosed(menu);
376                break;
377        }
378        super.onPanelClosed(featureId, menu);
379    }
380
381    /**
382     * Dispatch onPause() to fragments.
383     */
384    @Override
385    protected void onPause() {
386        super.onPause();
387        mResumed = false;
388        if (mHandler.hasMessages(MSG_RESUME_PENDING)) {
389            mHandler.removeMessages(MSG_RESUME_PENDING);
390            mFragments.dispatchResume();
391        }
392        mFragments.dispatchPause();
393    }
394
395    /**
396     * Dispatch onResume() to fragments.
397     */
398    @Override
399    protected void onResume() {
400        super.onResume();
401        mHandler.sendEmptyMessage(MSG_RESUME_PENDING);
402        mResumed = true;
403        mFragments.execPendingActions();
404    }
405
406    /**
407     * Dispatch onResume() to fragments.
408     */
409    @Override
410    protected void onPostResume() {
411        super.onPostResume();
412        mHandler.removeMessages(MSG_RESUME_PENDING);
413        mFragments.dispatchResume();
414        mFragments.execPendingActions();
415    }
416
417    /**
418     * Dispatch onPrepareOptionsMenu() to fragments.
419     */
420    @Override
421    public boolean onPreparePanel(int featureId, View view, Menu menu) {
422        if (featureId == Window.FEATURE_OPTIONS_PANEL && menu != null) {
423            if (mOptionsMenuInvalidated) {
424                mOptionsMenuInvalidated = false;
425                menu.clear();
426                onCreatePanelMenu(featureId, menu);
427            }
428            boolean goforit = super.onPreparePanel(featureId, view, menu);
429            goforit |= mFragments.dispatchPrepareOptionsMenu(menu);
430            return goforit && menu.hasVisibleItems();
431        }
432        return super.onPreparePanel(featureId, view, menu);
433    }
434
435    /**
436     * Retain all appropriate fragment and loader state.  You can NOT
437     * override this yourself!  Use {@link #onRetainCustomNonConfigurationInstance()}
438     * if you want to retain your own state.
439     */
440    @Override
441    public final Object onRetainNonConfigurationInstance() {
442        if (mStopped) {
443            doReallyStop(true);
444        }
445
446        Object custom = onRetainCustomNonConfigurationInstance();
447
448        ArrayList<Fragment> fragments = mFragments.retainNonConfig();
449        boolean retainLoaders = false;
450        if (mAllLoaderManagers != null) {
451            // prune out any loader managers that were already stopped and so
452            // have nothing useful to retain.
453            for (int i=mAllLoaderManagers.size()-1; i>=0; i--) {
454                LoaderManagerImpl lm = mAllLoaderManagers.valueAt(i);
455                if (lm.mRetaining) {
456                    retainLoaders = true;
457                } else {
458                    lm.doDestroy();
459                    mAllLoaderManagers.removeAt(i);
460                }
461            }
462        }
463        if (fragments == null && !retainLoaders && custom == null) {
464            return null;
465        }
466
467        NonConfigurationInstances nci = new NonConfigurationInstances();
468        nci.activity = null;
469        nci.custom = custom;
470        nci.children = null;
471        nci.fragments = fragments;
472        nci.loaders = mAllLoaderManagers;
473        return nci;
474    }
475
476    /**
477     * Save all appropriate fragment state.
478     */
479    @Override
480    protected void onSaveInstanceState(Bundle outState) {
481        super.onSaveInstanceState(outState);
482        Parcelable p = mFragments.saveAllState();
483        if (p != null) {
484            outState.putParcelable(FRAGMENTS_TAG, p);
485        }
486    }
487
488    /**
489     * Dispatch onStart() to all fragments.  Ensure any created loaders are
490     * now started.
491     */
492    @Override
493    protected void onStart() {
494        super.onStart();
495
496        mStopped = false;
497        mReallyStopped = false;
498        mHandler.removeMessages(MSG_REALLY_STOPPED);
499
500        if (!mCreated) {
501            mCreated = true;
502            mFragments.dispatchActivityCreated();
503        }
504
505        mFragments.noteStateNotSaved();
506        mFragments.execPendingActions();
507
508        if (!mLoadersStarted) {
509            mLoadersStarted = true;
510            if (mLoaderManager != null) {
511                mLoaderManager.doStart();
512            } else if (!mCheckedForLoaderManager) {
513                mLoaderManager = getLoaderManager(-1, mLoadersStarted, false);
514            }
515            mCheckedForLoaderManager = true;
516        }
517        // NOTE: HC onStart goes here.
518
519        mFragments.dispatchStart();
520        if (mAllLoaderManagers != null) {
521            for (int i=mAllLoaderManagers.size()-1; i>=0; i--) {
522                LoaderManagerImpl lm = mAllLoaderManagers.valueAt(i);
523                lm.finishRetain();
524                lm.doReportStart();
525            }
526        }
527    }
528
529    /**
530     * Dispatch onStop() to all fragments.  Ensure all loaders are stopped.
531     */
532    @Override
533    protected void onStop() {
534        super.onStop();
535
536        mStopped = true;
537        mHandler.sendEmptyMessage(MSG_REALLY_STOPPED);
538
539        mFragments.dispatchStop();
540    }
541
542    // ------------------------------------------------------------------------
543    // NEW METHODS
544    // ------------------------------------------------------------------------
545
546    /**
547     * Use this instead of {@link #onRetainNonConfigurationInstance()}.
548     * Retrieve later with {@link #getLastCustomNonConfigurationInstance()}.
549     */
550    public Object onRetainCustomNonConfigurationInstance() {
551        return null;
552    }
553
554    /**
555     * Return the value previously returned from
556     * {@link #onRetainCustomNonConfigurationInstance()}.
557     */
558    public Object getLastCustomNonConfigurationInstance() {
559        NonConfigurationInstances nc = (NonConfigurationInstances)
560                getLastNonConfigurationInstance();
561        return nc != null ? nc.custom : null;
562    }
563
564    void supportInvalidateOptionsMenu() {
565        if (android.os.Build.VERSION.SDK_INT >= HONEYCOMB) {
566            // If we are running on HC or greater, we can use the framework
567            // API to invalidate the options menu.
568            ActivityCompatHoneycomb.invalidateOptionsMenu(this);
569            return;
570        }
571
572        // Whoops, older platform...  we'll use a hack, to manually rebuild
573        // the options menu the next time it is prepared.
574        mOptionsMenuInvalidated = true;
575    }
576
577    /**
578     * Print the Activity's state into the given stream.  This gets invoked if
579     * you run "adb shell dumpsys activity <activity_component_name>".
580     *
581     * @param prefix Desired prefix to prepend at each line of output.
582     * @param fd The raw file descriptor that the dump is being sent to.
583     * @param writer The PrintWriter to which you should dump your state.  This will be
584     * closed for you after you return.
585     * @param args additional arguments to the dump request.
586     */
587    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
588        if (android.os.Build.VERSION.SDK_INT >= HONEYCOMB) {
589            // XXX This can only work if we can call the super-class impl. :/
590            //ActivityCompatHoneycomb.dump(this, prefix, fd, writer, args);
591        }
592        writer.print(prefix); writer.print("Local FragmentActivity ");
593                writer.print(Integer.toHexString(System.identityHashCode(this)));
594                writer.println(" State:");
595        String innerPrefix = prefix + "  ";
596        writer.print(innerPrefix); writer.print("mCreated=");
597                writer.print(mCreated); writer.print("mResumed=");
598                writer.print(mResumed); writer.print(" mStopped=");
599                writer.print(mStopped); writer.print(" mReallyStopped=");
600                writer.println(mReallyStopped);
601        writer.print(innerPrefix); writer.print("mLoadersStarted=");
602                writer.println(mLoadersStarted);
603        if (mLoaderManager != null) {
604            writer.print(prefix); writer.print("Loader Manager ");
605                    writer.print(Integer.toHexString(System.identityHashCode(mLoaderManager)));
606                    writer.println(":");
607            mLoaderManager.dump(prefix + "  ", fd, writer, args);
608        }
609        mFragments.dump(prefix, fd, writer, args);
610    }
611
612    void doReallyStop(boolean retaining) {
613        if (!mReallyStopped) {
614            mReallyStopped = true;
615            mRetaining = retaining;
616            mHandler.removeMessages(MSG_REALLY_STOPPED);
617            onReallyStop();
618        }
619    }
620
621    /**
622     * Pre-HC, we didn't have a way to determine whether an activity was
623     * being stopped for a config change or not until we saw
624     * onRetainNonConfigurationInstance() called after onStop().  However
625     * we need to know this, to know whether to retain fragments.  This will
626     * tell us what we need to know.
627     */
628    void onReallyStop() {
629        if (mLoadersStarted) {
630            mLoadersStarted = false;
631            if (mLoaderManager != null) {
632                if (!mRetaining) {
633                    mLoaderManager.doStop();
634                } else {
635                    mLoaderManager.doRetain();
636                }
637            }
638        }
639
640        mFragments.dispatchReallyStop();
641    }
642
643    // ------------------------------------------------------------------------
644    // FRAGMENT SUPPORT
645    // ------------------------------------------------------------------------
646
647    /**
648     * Called when a fragment is attached to the activity.
649     */
650    public void onAttachFragment(Fragment fragment) {
651    }
652
653    /**
654     * Return the FragmentManager for interacting with fragments associated
655     * with this activity.
656     */
657    public FragmentManager getSupportFragmentManager() {
658        return mFragments;
659    }
660
661    /**
662     * Modifies the standard behavior to allow results to be delivered to fragments.
663     * This imposes a restriction that requestCode be <= 0xffff.
664     */
665    @Override
666    public void startActivityForResult(Intent intent, int requestCode) {
667        if (requestCode != -1 && (requestCode&0xffff0000) != 0) {
668            throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");
669        }
670        super.startActivityForResult(intent, requestCode);
671    }
672
673    /**
674     * Called by Fragment.startActivityForResult() to implement its behavior.
675     */
676    public void startActivityFromFragment(Fragment fragment, Intent intent,
677            int requestCode) {
678        if (requestCode == -1) {
679            super.startActivityForResult(intent, -1);
680            return;
681        }
682        if ((requestCode&0xffff0000) != 0) {
683            throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");
684        }
685        super.startActivityForResult(intent, ((fragment.mIndex+1)<<16) + (requestCode&0xffff));
686    }
687
688    void invalidateSupportFragmentIndex(int index) {
689        //Log.v(TAG, "invalidateFragmentIndex: index=" + index);
690        if (mAllLoaderManagers != null) {
691            LoaderManagerImpl lm = mAllLoaderManagers.get(index);
692            if (lm != null && !lm.mRetaining) {
693                lm.doDestroy();
694                mAllLoaderManagers.remove(index);
695            }
696        }
697    }
698
699    // ------------------------------------------------------------------------
700    // LOADER SUPPORT
701    // ------------------------------------------------------------------------
702
703    /**
704     * Return the LoaderManager for this fragment, creating it if needed.
705     */
706    public LoaderManager getSupportLoaderManager() {
707        if (mLoaderManager != null) {
708            return mLoaderManager;
709        }
710        mCheckedForLoaderManager = true;
711        mLoaderManager = getLoaderManager(-1, mLoadersStarted, true);
712        return mLoaderManager;
713    }
714
715    LoaderManagerImpl getLoaderManager(int index, boolean started, boolean create) {
716        if (mAllLoaderManagers == null) {
717            mAllLoaderManagers = new HCSparseArray<LoaderManagerImpl>();
718        }
719        LoaderManagerImpl lm = mAllLoaderManagers.get(index);
720        if (lm == null) {
721            if (create) {
722                lm = new LoaderManagerImpl(this, started);
723                mAllLoaderManagers.put(index, lm);
724            }
725        } else {
726            lm.updateActivity(this);
727        }
728        return lm;
729    }
730}
731