Android Development Tutorial: Android Invoke Activity simple method

Source: Internet
Author: User

It's a lot of trouble to call another apk in an apk without looking at the school's instructional video, and sometimes it's scary to meet them, but after watching the Android development tutorial video, I think it's a simple thing to do. So write a small article for reference.

The system provides a lot of activity that can be called directly, which can be called by the specified intent, such as open search:

Java code

1. Intent Intent = new Intent (intent.action_web_search);

2. Intent.putextra (Searchmanager.query, "searchstring")

3. StartActivity (Intent);

Intent.action_web_search is a string that is the identity of the "search" activity, and extra is some data passed to the activity. After sending out this intent, the system knows what activity to invoke based on the ACTION string intent.action_web_search, and if there is a duplicate name, a selection dialog box pops up. Then open the activity and implement what you want to do.

So, how do we come to realize it ourselves.
First of all, write an activity, in the androidmanifest.xml inside the intent-filter, give this activity named,

XML code

1. <intent-filter>

2. <action android:name= "Chroya.foo"/>

3. <category android:name= "Android.intent.category.DEFAULT"/>

4. </intent-filter>

and then install. Once the installation is complete, you will find that the program is not found in the system. Don't worry, it's actually installed in the phone, but because he's not main, the system doesn't think of him as a application entry program.

And to open this activity, only the person who knows its name can. Use the same as the intent of the system. Its name is defined as "Chroya.foo", so it can be called with this string:

Java code

1. Intent Intent = new Intent ("Chroya.foo");

2. StartActivity (Intent);

I use the intent of the system I just lifted to show that its activity uses getintent (). Getbundleextra (Searchmanager.query) to receive the passed in search string parameter. And this searchmanager.query is the key word. If you want to do this yourself, you just need to define the keyword and then take it from the Bundleextra.


More Android Development tutorials at: Http://www.maiziedu.com/course/android/


Android Development Tutorial: Android Invoke Activity simple method

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.