Starting from scratch Android development-how to start activity with intent

Source: Internet
Author: User

To start another activity, you can have methods useful setclass () and component Name
1. Let's start with an activity method in SetClass:
Intent Intent = new Intent ();
Intent.setclass (this, createplaylist.class)//parameter one for the current package context,t the current activity context is this, Other package may use the Createpackagecontex () parameter two for the class name of the activity you want to open
StartActivity (Intent);
2. The way to open by component name
Intent Intent = new Intent ();
Intent.setaction (Intent.action_main); Add some features to see the intent document, the related properties of the introduction
Intent.addcategory (Intent.category_launcher);
Intent.setflags (Intent.flag_activity_new_task | intent.flag_activity_reset_task_if_needed);

Pass some data through the bundle to the activity to be opened
Bundle bundle = new bundle ();
Bundle.putstring ("Data", New String ("Hello World");
Intent.putextras (bundle);

Intent.setcomponent (New ComponentName (
New String ("Com.android.testActivity"), new String ("com.android.testActivity.testActivity"));
StartActivity (Intent);

Starting from scratch Android development-how to start activity with intent

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.