注意,这里的SubActivity的launchMode属性配置为"singleTask"。
再来看界面配置文件。
它们定义在res/layout目录中,main.xml文件对应MainActivity的界面:
[html] view plaincopy
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:gravity="center"> android:id="@+id/button_start"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:text="@string/start" >
而sub.xml对应SubActivity的界面:[html] view plaincopy
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:gravity="center"> android:id="@+id/button_finish"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:text="@string/finish" >
字符串文件位于res/values/strings.xml文件中:[html] view plaincopy
- Task
- Sub Activity
- Start singleTask activity
- Finish activity
***,我们还要在工程目录下放置一个编译脚本文件Android.mk:
- [html] view plaincopyLOCAL_PATH:= $(call my-dir)
- include $(CLEAR_VARS)
- LOCAL_MODULE_TAGS := optional
- LOCAL_SRC_FILES := $(call all-subdir-java-files)
- LOCAL_PACKAGE_NAME := Task
- include $(BUILD_PACKAGE)