android launcher开发(6) Launcher暂停,停止,销毁

当一个新的Activity被重新启动,上一个activity会进入onpause()状态。那么默认onpause中实现了什么呢?

  if (DEBUG_LIFECYCLE) Slog.v(TAG, "onPause " + this);
        getApplication().dispatchActivityPaused(this);
        通知注册在应用程序的activity生命周期监听接口
        mCalled = true;

Launcher的onpause()

 protected void onPause() {
//       启用一个快捷方式的安装队列,因为launcher提供了一个接口,保证应用程序在安装的时候
//        往桌面是添加快捷方式,这样说启用一个队列保证在launcher回来的时候进行操作
        // Ensure that items added to Launcher are queued until Launcher returns
        InstallShortcutReceiver.enableInstallQueue();

        super.onPause();

        mPaused = true;
//        停止拖拽动作,并且重置拖拽动作的更新时间
        mDragController.cancelDrag();
        mDragController.resetLastGestureUpTime();

        // We call onHide() aggressively. The custom content callbacks should be able to
        // debounce excess onHide calls.
//        如果有定制的组件,怎进行隐藏
        if (mWorkspace.getCustomContentCallbacks() != null) {
            mWorkspace.getCustomContentCallbacks().onHide();
        }

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onPause();
        }
    }

Onstart

和上面的onpause类似,标识mcalled,表明我们已经调用了这个基类,让activity里面的fragment处于start状态,告诉监听接口,activity处于onstart

 protected void onStart() {
        if (DEBUG_LIFECYCLE) Slog.v(TAG, "onStart " + this);
        mCalled = true;

        mFragments.doLoaderStart();

        getApplication().dispatchActivityStarted(this);
    }

在launcher的onstar里面进行的操作比较少,只是使动画处于显示状态。

{
        super.onStart();
        FirstFrameAnimatorHelper.setIsVisible(true);

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onStart();
        }
    }

onStop()

在这个状态中,launcher做的事情并不是很多
把动画处于隐藏状态

  @Override
    protected void onStop() {
        super.onStop();
        FirstFrameAnimatorHelper.setIsVisible(false);

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onStop();
        }
    }

ondestory

这个状态是activity的最后一个状态,需要进行数据的清理工作。

protected void onDestroy() {
        if (DEBUG_LIFECYCLE) Slog.v(TAG, "onDestroy " + this);
        mCalled = true;

        // dismiss any dialogs we are managing.,关闭管理的所有dialog
        if (mManagedDialogs != null) {
            final int numDialogs = mManagedDialogs.size();
            for (int i = 0; i < numDialogs; i++) {
                final ManagedDialog md = mManagedDialogs.valueAt(i);
                if (md.mDialog.isShowing()) {
                    md.mDialog.dismiss();
                }
            }
            mManagedDialogs = null;
        }

        // close any cursors we are managing.关闭所管理的游标
        synchronized (mManagedCursors) {
            int numCursors = mManagedCursors.size();
            for (int i = 0; i < numCursors; i++) {
                ManagedCursor c = mManagedCursors.get(i);
                if (c != null) {
                    c.mCursor.close();
                }
            }
            mManagedCursors.clear();
        }

        // Close any open search dialog,关闭的打开的搜索框
        if (mSearchManager != null) {
            mSearchManager.stopSearch();
        }

        getApplication().dispatchActivityDestroyed(this);
    }

这个是Launcher中ondestory()进行的处理

  @Override
    public void onDestroy() {
        super.onDestroy();

        // Remove all pending runnables,移除所有任务
        mHandler.removeMessages(ADVANCE_MSG);
        mHandler.removeMessages(0);
        mWorkspace.removeCallbacks(mBuildLayersRunnable);

        // Stop callbacks from LauncherModel,解除launcher与launchermodel的关联
        LauncherAppState app = (LauncherAppState.getInstance());

        // It's possible to receive onDestroy after a new Launcher activity has
        // been created. In this case, don't interfere with the new Launcher.
        if (mModel.isCurrentCallbacks(this)) {
            mModel.stopLoader();
            app.setLauncher(null);
        }

        try {
//            停止运行小部件
            mAppWidgetHost.stopListening();
        } catch (NullPointerException ex) {
            Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
        }
        mAppWidgetHost = null;

        mWidgetsToAdvance.clear();

        TextKeyListener.getInstance().release();
//注销监听
        unregisterReceiver(mCloseSystemDialogsReceiver);
//清理调节小部件尺寸的指示框
        mDragLayer.clearAllResizeFrames();
//        移除launcher的所有view
        ((ViewGroup) mWorkspace.getParent()).removeAllViews();
//        移除所有桌面页
        mWorkspace.removeAllWorkspaceScreens();
        mWorkspace = null;
        mDragController = null;
//停止动画
        LauncherAnimUtils.onDestroyActivity();

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onDestroy();
        }
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值