Four loading modes of activity--Singletask and singleinstance mode 2011-11-02 21:23:30
Category: Embedded
The activation mode of the activity can be specified by the attributes of the <activity> element in the Androidmanifest.xml file, with a total of 4 modes:
|
<activity android:name= "Activitymain" android:launchmode= "Singletask" ></activity> |
- Standard
- Singletop
- Singletask
- singleinstance
The 4 model is divided into two categories, Standard and signletop belong to a class, Singletask and Signleinstance belong to another category.
An instance of the activity of the standard and Singletop properties can belong to any task, and can be anywhere on the activity stack. A more typical case is that a task's code executes startactivity (), and if the passed Intent object does not contain the Flag_activity_new_task attribute, the specified ACTIVITY is called by the task, This loads the task's activity stack. The difference between standard and singletop is that the activity of standard mode creates a new instance when called, and all instances process the same intent object, but for Singletop mode activity, If the called task already has one such activity at the top of the stack, there will be no new instance creation, and the task will process the intent object using the activity instance at the top of the current, in other words, if the called task contains a singletop that is not at the top of the stack activity, or the task at the top of the stack for singletop activity is not the currently called task, then there will still be a new activity object being created.
The activity of the Singletask and SingleInstance modes can only be used to initiate tasks where the activity is always at the bottom of the activity stack, and only one task can be instantiated once. The difference between the two is that for the activity of the singleinstance mode, if there is such activity in the activity stack of the task, it will be the only activity in the stack, and the Intent that the current task receives is handled by it. Other activity initiated by it will be launched in other tasks, and for Singletask mode activity, it can be created at the bottom of the stack with other activity above it, but If the activity is not on the top of the stack when the intent object is sent to the activity, the intent object will be discarded, but the interface will switch to the current activity.
Http://www.cnblogs.com/hibraincol/archive/2011/04/11/2012719.html
The following is a summary of the functional implementations required for personal testing by laoyang1018:
Refer to QQ Sync Assistant Qqpim
<?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Belson.android.uECG"
Android:versioncode= "1"
Android:versionname= "1.0" >
<USES-SDK android:minsdkversion= "8"/>
<application android:icon= "@drawable/ecg_logo" android:label= "@string/app_name" >
<activity android:name= ". SplashScreen"
Android:label= "@string/app_name"
Android:launchmode= "Singletop"
android:screenorientation= "Landscape"
Android:configchanges= "Keyboardhidden|orientation"
Android:theme= "@android: Style/theme.notitlebar.fullscreen" >
<!--landscape Set Force horizontal screen-<!--Theme.NoTitleBar.Fullscreen Set start screen Untitled fullscreen--
<!--singletop Mode setting is always run from the activity of the startup interface when the program is not running--
<!--for Singletop mode activity, if the called task already has one such activity at the top of the stack, there will be no new instance creation, and the task will use the current top activity instance to process the intent object.
In other words, if the called task contains a singletop activity that is not at the top of the stack, or if the task at the top of the stack for singletop activity is not the currently called task, then there will still be a new activity object created-- >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name= ". Uecgactivity"
Android:launchmode= "Singletask"
android:screenorientation= "Landscape"
Android:configchanges= "Keyboardhidden|orientation"
Android:theme= "@android: Style/theme.notitlebar.fullscreen" > <!--Settings Main interface Untitled fullscreen--
<!--android:launchmode= "singleinstance" here to temporarily remove SingleInstance mode, because this mode causes the preset data to not be returned-
<!--singletask Mode setting jumps directly to the previous activity without re-oncreate the program from the notification bar when it brings up the currently running program
<!--activity for Singletask mode, which can have other activity created at the bottom of the stack,
However, if the activity is not on the top of the stack when the intent object is sent to the activity, the intent object will be discarded, but the interface will switch to the current activity. -
<!--set Keyboardhidden|orientation This ensures that from entry to activity always a horizontal screen does not appear multiple times oncreate and OnDestroy--
</activity>
<service android:enabled= "true" android:name= ". Socketservice ">
<intent-filter>
<action android:name= "Belson.android.uECG.SocketService"/>
</intent-filter>
</service>
</application>
<uses-permission android:name= "Android.permission.CHANGE_NETWORK_STATE" ></uses-permission>
<uses-permission android:name= "Android.permission.CHANGE_WIFI_STATE" ></uses-permission>
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE" ></uses-permission>
<uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE" ></uses-permission>
<uses-permission android:name= "Android.permission.INTERNET" ></uses-permission>
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission> <!-- Add permissions to the SDcard operation--
<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS" ></uses-permission> < !--Add permissions to the SDcard operation--
</manifest>