Android technology 7: Activity startup mode, androidactivity

Source: Internet
Author: User

Android technology 7: Activity startup mode, androidactivity

1. Activity Startup Mode

In Android, four startup modes of Activity

  • Standard (default)
  • SingleTop
  • SingleTask
  • SingleInstance

The four startup modes are configured in AndroidManifest. xml to set parameters in each activity to android: launchMode.

2. pattern features

Standard: In this mode, a new instance is generated each time it is started through Intent. Android: launchMode is not configured. The default value is standard.

SingleTop: This mode is similar to standard. The difference is that if the current Activity is at the top of the stack, intent will not generate a new instance when starting the Activity and reuse the original Instance. However, if the Activity is not currently at the top of the stack, a new instance is generated. If the intent parameter FLAG_ACTIVITY_NEW_TASK is specified explicitly, the task is restarted.

SingleTask: In this mode, the Activity only has one instance. If an instance of the Activity already exists in a Task, it is no longer started and will be reused every time. If the Activity is at the bottom of the stack of the Task, will be adjusted to the top of the stack.

SingleInstance: This mode is the same as singleTask. The only difference is that in this mode, an Activity has a task independently and is not shared with other activities. Every Activity is reused, only one instance can be created globally.

3. Demo

 


Android Development

This problem depends on how you do it. The satellite view and the hybrid mode are two activities or one Activity.
For two activities, you can modify the Activity filter in AndroidManifest. xml as follows:
<Activity android: name = ". testActivity" android: label = "@ string/app_name">
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>
<Intent-filter>
<Action android: name = "test. app. testActivity"/>
<Category android: name = "android. intent. category. DEFAULT"/>
</Intent-filter>
</Activity>
Add a DEFAULT filter to both the satellite view and hybrid mode. You can call the Activity by using the android: name Defined by Intent.

If you are in an Activity, you can achieve this through sharing preferences. When you exit the activity, record whether it is a satellite view or a hybrid mode. Next time, read the mode and load different interfaces and data.

Ladies and gentlemen: android can configure the first started Activity in AndroidManifestxml.

<Application
Android: name = ". TextApplication"
Android: icon = "@ drawable/ic_launcher"
Android: label = "@ string/app_name"
Android: theme = "@ android: style/Theme. Light. NoTitleBar. Fullscreen">
<Activity
Android: name = ". HomeActivity"
Android: launchMode = "singleTask"
Android: label = "@ string/app_name"
Android: screenOrientation = "landscape">
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>

<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>

This. HomeActivity is your default first startup Activity. You just need to give it the first startup path.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.