Analysis of Different Android Interface Application Methods

Source: Internet
Author: User

In the Android operating system, some operations on the interface are the most basic knowledge points that you need to master. We can use this article to introduce the method of interaction between Android interfaces to get a preliminary understanding of some of the interface application skills in the Android system.

  • Modify the Android simulator size at will
  • Comprehensive Explanation of Android Multimedia Framework source code
  • How to correctly use the Android command line Startup Program
  • How to query contact information in Android
  • Android smart pointer usage

Now, we have learned that our actual programs are only transferred in one interface, but in fact, we need to write some pages for interaction between Android interfaces, such as the call interface, we may need to pop up a list of phone numbers.

On the Windows interface, we all know that the divided into mode dialog box and the Do-not-work dialog box, but on the mobile interface, we cannot imagine that, it is difficult for my interface to be displayed in one interface at the same time, because the main screen is very small. Therefore, in the Android system, there are still many differences between the interface and our Windows. At the same time, only one interface (Activity) can be displayed on the Android interface, but the interface can be tuned in the subinterface, therefore, in an enabled program, if the sub-interface is called, an interface stack is generated later, as shown in the following figure:

In the system, an optimization method is that a program can have only one Activity. If the subinterface is called, the program is hidden in the background. if the system is insufficient, the system will reclaim the pop-up Activity, with only one original Activity left. This main Activity can be said to be the entry of the program.

After talking about this, let's take a look at the specific implementation methods of the Android interface interaction. How can we bring up another Activity in one Activity:

Generally, in our general practice, the startup interface is nothing more than specifying a specific class in the New Territories, and then calling a method. Let's look at the Code:

 
 
  1. Intent intent = new Intent (MainActivity. this, NewForm. class );
  2. StartActivity (intent); // or startActivityForResult (intent, 1 );

This code is not complex. We analyze one item:

Intent

I don't know how to translate this. It is mainly used for communication between interfaces. Of course, there may be more functions. I will learn more later! New Intent (MainActivity. this, NewForm. class); we can see that NewForm is passed in.

StartActivity

Start the interface function. The input parameter is the defined intent.

StartActivityForResult

This is also a function of the startup interface, but the difference with startActivity is that after this method starts the interface, this interface can pass the return value to the parent form. As for this parameter 1, I am not very familiar with it yet. Please use it first.

In fact, this step is easy for us to accept. Well, let's take a look at Step 2 and how to pass parameters? For example, I want to create an interface to bring up a list of Members. After selecting a person, I close the interface and the main interface will know which value I have selected.

In the implementation of interactive debugging on the Android interface, we use Uri to pass the value. This is a string-spliced information, and there is also such a class in the system, why use a Uri as a string instead of an Object? In fact, there are a lot of information transmitted by the Object, but it is not standard. After this program is packaged with an Object, other programs do not know how to explain your Object. A Uri string can be used to locate HTML documents, images, video clips, programs, and other resources by a Universal Resource Identifier ("URI.

The Uri is divided into three parts: the naming mechanism for accessing resources; The host name for storing resources; the name of the resource itself, represented by the path.

For example, "Http: // www.baidu.com/text/xxx.html?here httpis The Name Of The naming convention), www.baidu.com is the resource location, and text/xxxlhtml is the resource name. In the Android system, if "content: // contacts/1" indicates the number 1st in the contacts Contact in the system, it is easy to locate a resource, with these shared formats, You can seamlessly interact with other processing programs in the system, such

 
 
  1. Intent intent = new Intent(Intent.ACTION_DIAL,  
  2. Uri.parse(“tel:555-2368”));  
  3. startActivity(intent); 

It can be used to start a dialup program.

After the parameter format is defined, we can use

 
 
  1. Uri data = Uri. parse ("xxxx ");
  2. Intent. setData (data); // PASS Parameters

In the sub-interface, we use

 
 
  1. Intent intent = getIntent();  
  2. Uri data = intent.getData(); 

To receive incoming parameters.

In the sub-interface, when the interface is closed, there are also OK and cancel points,

When you click "OK", you can perform the following operations:

 
 
  1. Uri data = Uri. parse ("Content: //" + edit. getText ());
  2. Intent result = new Intent (null, data );
  3. SetResult (RESULT_ OK, result); // transmits the confirmation information and parameters.
  4. Finish ();

When the cancel button is clicked, the process is as follows:

 
 
  1. SetResult (RESULT_CANCELED, null );
  2. // Transfer the cancellation information and Parameters
  3. Finish ();

In the parent interface, we use a public void onActivityResult (int requestCode, int resultCode, Intent data) Inheritance function to process the returned messages of all subinterfaces. The request code, return code, and return value, such:

 
 
  1. public void onActivityResult(int requestCode, 
    int resultCode, Intent data) {  
  2. super.onActivityResult(requestCode, resultCode, data);  
  3. if (resultCode == Activity.RESULT_OK) {  
  4. Uri horse = data.getData();  
  5. TextView txt = (TextView)findViewById(R.id.TextView01);  
  6. txt.setText(horse.toString());  
  7. }  

This section describes how to perform interactive debugging on the Android interface.

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.