In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to achieve interface intermodulation in Android", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to achieve interface intermodulation in Android" article.
In the system, there is an optimization way is that a program can have only one Activity. If you call the subinterface, then hide the program in the background. If the system is insufficient, the system will take back the pop-up Activity, leaving only the original Activity, the main Activity, which can also be said to be the entrance of the program.
Having said that, let's take a look at the specific implementation of Android interface intermodulation and how to pop up another Activity in one Activity:
Usually, according to our routine, the startup interface is nothing more than specifying a specific class of a new interface, and then calling a method, look at the code:
Intent intent = new Intent (MainActivity.this, NewForm.class); startActivity (intent); / / or startActivityForResult (intent, 1)
This code is not complicated, we analyze it one by one:
Intent
I don't know how to translate this specific. it is mainly used for the communication between interfaces. Of course, there may be more functions. I will learn about it later! New Intent (MainActivity.this, NewForm.class); the creation here shows that we have passed in the class NewForm.
StartActivity
Start the interface function, and the parameters passed in are the intent we defined.
StartActivityForResult
This is also a function that starts the interface, but the difference from startActivity is that after this method starts the interface, the interface can pass the return value to the parent form. As for this parameter 1, we don't know much about it yet, so use it first.
In fact, this step is easy for us to accept, good, and then understand the second step, how to pass the parameters? For example, I want to make an interface that pops up a list of people, selects a person, closes the interface, and then the main interface knows which value I have chosen.
In the Android interface Intermodulation implementation, we pass the value using Uri, which is a string splicing information, there is also such a class in the system, why not Object and use Uri a string, in fact, Object transmission of information is much, but not standard, this program uses Object to package, other programs do not know how to explain you this Object. And Uri a string is available to various resources HTML documents, images, video clips, programs, etc., by a common resource marker (Universal Resource Identifier, referred to as "URI") to locate.
The Uri is divided into three parts: the naming mechanism to access the resource; the hostname where the resource is stored; and the name of the resource itself, which is represented by the path.
For example, "Http://www.baidu.com/text/xxx.html" where Http is the naming mechanism (protocol name), www.baidu.com is the resource location, and text/xxxlhtml is the resource name. In Android systems, such as "content://contacts/1", it is easy to locate a resource in the number 1 of contacts (contacts) in the system. After using these common formats, you can seamlessly interact with other processors in the system, such as
Intent intent = new Intent (Intent.ACTION_DIAL, Uri.parse ("tel:555-2368")); startActivity (intent)
It can be used to start a dialing program.
Once the parameter format is defined, we can use it in the enabling interface.
Uri data = Uri.parse ("xxxx"); intent.setData (data); / / pass parameters
In the subinterface, we use the
Intent intent = getIntent (); Uri data = intent.getData ()
To receive the incoming parameters
In the sub-interface, when you close the interface, you can also confirm and cancel it.
We can do this when we click the OK button:
Uri data = Uri.parse ("Content://" + edit.getText ()); Intent result = new Intent (null, data); setResult (RESULT_OK, result); / / pass determination information, and parameter finish ()
When you click the cancel button, deal with it like this:
SetResult (RESULT_CANCELED, null); / / pass cancellation information, and parameter finish ()
In the parent interface, we handle the return messages of all child interfaces through a public void onActivityResult (int requestCode, int resultCode, Intent data) inheritance function. Here comes the request code, return code, and return value, such as:
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 ())
}
}
The above is about the content of this article on "how to achieve interface adjustment in Android". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.