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:
- Intent intent = new Intent (MainActivity. this, NewForm. class );
- 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
- Intent intent = new Intent(Intent.ACTION_DIAL,
- Uri.parse(“tel:555-2368”));
- startActivity(intent);
It can be used to start a dialup program.
After the parameter format is defined, we can use
- Uri data = Uri. parse ("xxxx ");
- Intent. setData (data); // PASS Parameters
In the sub-interface, we use
- Intent intent = getIntent();
- 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:
- Uri data = Uri. parse ("Content: //" + edit. getText ());
- Intent result = new Intent (null, data );
- SetResult (RESULT_ OK, result); // transmits the confirmation information and parameters.
- Finish ();
When the cancel button is clicked, the process is as follows:
- SetResult (RESULT_CANCELED, null );
- // Transfer the cancellation information and Parameters
- 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:
- public void onActivityResult(int requestCode,
int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (resultCode == Activity.RESULT_OK) {
- Uri horse = data.getData();
- TextView txt = (TextView)findViewById(R.id.TextView01);
- txt.setText(horse.toString());
- }
- }
This section describes how to perform interactive debugging on the Android interface.