An introduction to the difference between an Android explicit startup and an implicit start activity _android

Source: Internet
Author: User

Some time ago determined to persist in writing a blog, but found that their accumulation is indeed not much, so the holiday bubble library, read some valuable articles. Harvest a lot, today's article to share the main, common learning.

Why write an explicit start and an implicit start activity. This is from an interview, Baidu engineer asked, but later feel that their answer is not good, less talk, to get to the point.

As the title, Android's acitivity startup is roughly two ways: explicit startup and implicit startup. The following are described separately:

A: Explicitly start

For starters, this is most common, and the following code explains what an explicit startup is.

Copy Code code as follows:

Intent intent=new Intent (Mainactivity.this, Secondactivity.class);
StartActivity (Intent);

B: Implicit startup

The difference in implicit startup is that we don't need to be like intent (mainactivity.this, Secondactivity.class) This passes the argument and then start another activity. We need to add filter intentfilter to the intent.

<activity 
android:name= "com.example.android.tst.SecondActivity" 
android:label= "@string/title_ Activity_main "> 
<intent-filter> 
<action android:name=" Com.example.android.tst.SecondActivity "/> 
<category android:name=" Android.intent.category.DEFAULT " > 
</intent-filter> 
</activity>

In this way, we need to start another activity with just the following methods:

Copy Code code as follows:

Intent intent=new Intent ("com.example.android.tst.SecondActivity");
StartActivity (Intent);

Such an example would be more clear. Because not accustomed to Web page Editor Bowen, and not familiar with the attachment upload, the project will not upload, more hands most important!

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.