一步步深入了解android机制-1

来源:互联网 发布:淘宝35岁文艺女装店 编辑:程序博客网 时间:2024/05/18 01:15

首先,我们如果编写最简单的APP应用,比如hello world,只需要在oncreate函数中加入一下代码即可。

public class HelloWorld extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    TextView tv = new TextView(this);    tv.setText("Hello, World!");    setContentView(tv);}

那么,从点击应用到执行onCreate函数之间,android总共做了什么操作,在知道android的应用程序启动过程之前,我们需要知道android中launcher类的作用,它主要实现了主界面的一些操作,具体细节将在后续讨论。我们在主界面点击一个应用开始,就是执行了 launcher类的 onClick操作。

    /**     * Launches the intent referred by the clicked shortcut.     *     * @param v The view representing the clicked shortcut.     */    public void onClick(View v) {        // Make sure that rogue clicks don't get through while allapps is launching, or after the        // view has detached (it's possible for this to happen if the view is removed mid touch).        if (v.getWindowToken() == null) {            return;        }        if (mWorkspace.isSwitchingState()) {            return;        }        Object tag = v.getTag();        if (tag instanceof ShortcutInfo) {            // Open shortcut            final Intent intent = ((ShortcutInfo) tag).intent;            int[] pos = new int[2];            v.getLocationOnScreen(pos);            intent.setSourceBounds(new Rect(pos[0], pos[1],                    pos[0] + v.getWidth(), pos[1] + v.getHeight()));            boolean success = startActivitySafely(intent, tag);            if (success && v instanceof BubbleTextView) {                mWaitingForResume = (BubbleTextView) v;                mWaitingForResume.setStayPressed(true);            }        } else if (tag instanceof FolderInfo) {            if (v instanceof FolderIcon) {                FolderIcon fi = (FolderIcon) v;                handleFolderClick(fi);            }        } else if (v == mAllAppsButton) {            if (mState == State.APPS_CUSTOMIZE) {                showWorkspace(true);            } else {                onClickAllAppsButton(v);            }        }    }




0 0
原创粉丝点击