1、如果在一个activity A的onCreate()或者onResume()方法中调用方法startActivity()启动另一个activity B,那么activity B会在activity A的onResume方法结束后才启动,为了防止启动activity B时出现画面闪烁,activity A的window不会显示。


     * Launch an activity for which you would like a result when it finished.
     * When this activity exits, your
     * onActivityResult() method will be called with the given requestCode. 
     * Using a negative requestCode is the same as calling 
     * {@link #startActivity} (the activity is not launched as a sub-activity).
     * <p>Note that this method should only be used with Intent protocols
     * that are defined to return a result.  In other protocols (such as
     * {@link Intent#ACTION_MAIN} or {@link Intent#ACTION_VIEW}), you may
     * not get the result when you expect.  For example, if the activity you
     * are launching uses the singleTask launch mode, it will not run in your
     * task and thus you will immediately receive a cancel result.
     * <p>As a special case, if you call startActivityForResult() with a requestCode 
     * >= 0 during the initial onCreate(Bundle savedInstanceState)/onResume() of your
     * activity, then your window will not be displayed until a result is 
     * returned back from the started activity.  This is to avoid visible 
     * flickering when redirecting to another activity. 
     * <p>This method throws {@link android.content.ActivityNotFoundException}
     * if there was no Activity found to run the given Intent.
     * @param intent The intent to start.
     * @param requestCode If >= 0, this code will be returned in
     *                    onActivityResult() when the activity exits.
     * @param options Additional options for how the Activity should be started.
     * See {@link android.content.Context#startActivity(Intent, Bundle)
     * Context.startActivity(Intent, Bundle)} for more details.
     * @throws android.content.ActivityNotFoundException
     * @see #startActivity 
    public void startActivityForResult(Intent intent, int requestCode, Bundle options) {

2、layout A使用<include >包含另外一个layout B时,覆盖layout B中的属性满足两个规则:

1)<include >的android:id属性会覆盖layout B的android:id属性;

2)<include >只能覆盖layout B中的android:layout_相关的属性,并且至少覆盖android:layout_widthandroid:layout_height属性,否则<include >中包含的layout相关的属性会被忽略。


public class DemoActivity extends Activity {
    boolean stopThread = false;

    public void onCreate(Bundle savedInstanceState) {
        // 创建新线程
        new Thread(new Runnable() {
            public void run() {
                Log.d(TAG, "thread is Runing....");
                while (!stopThread) {
                    // do something
                Log.d(TAG, "thread is over....");

    protected void onDestroy() {
        // 置位线程结束标志
        stopThread = true;

4、Android的Task是完成一项具体的工作所涉及的Activity(可能来自不同的Application)的集合,这些Activity按被启动的顺序放在一个Back Stack中。

“A task is a collection of activities that users interact withwhen performing a certain job. The activities are arranged in a stack (the "back stack"), in theorder in which each activity is opened.” Tasks and Back Stack

想对作者说点什么? 我来说一句


2009年12月18日 1.16MB 下载