Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize data transfer in Android

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge points about how to achieve data transmission in Android. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.

Passing values between Activity

Passing values between Activity is done through Intent. I believe that brothers with some foundation will know that we use the Extra part of Intent to store the data we want to pass. Examples are as follows:

Intent I = new Intent (this, YourClass.class); i.putExtra (YOURDATA, data); startActivity (I); Intent I = new Intent (this, YourClass.class); i.putExtra (YOURDATA, data); startActivity (I)

What needs to be noted here is putExtra method. Its * parameters must have a package prefix, which means we cannot specify a String at will, but must have package prefix. For example, we can define YOURDATA as follows:

Public final static String YOURDATA =

"com.javaeye.notfatboy.testArg"

Ublic final static String YOURDATA =

"com.javaeye.notfatboy.testArg"

The second parameter can be int, long, char and so on. For more information, please see putExtra ().

Detailed explanation of the method of judging Network State by Android

Interpretation of Android Unit Test Source Code

Android Jni code example explains

Analysis of the specific operation method of Android installation and uninstall program

Explanation of Android Shell command

In fact, Intent is much more widely used, and we can pass values through Extra anywhere we use Intent, and by extension, we can also pass values to Service, to Broadcast Receiver, which also illustrates another problem, that is, we can pass values between different processes and threads in this way, because Activity,Service,Broadcast these Components can be in different processes or threads. This is also a lightweight way for processes and threads to communicate with each other provided by Android.

In addition, Android also provides us with a slightly more complex value passing mechanism, in the case of Thread, we can use Message Queue to achieve Android data transmission.

Messag Queue

Message Queue is a very useful and interesting mechanism. Suppose we have two Thread, one is thread An and the other is thread B. Thread A has a Message Queue and corresponds to a Handler to process the Message, which means that as long as thread B gets the reference of the Handler, it can send a message to Thread A. Examples are as follows:

Public class ThreadB extends Thread {.... Public void run () {... String str = "Test String"; Message msg = mHandler.obtainMessage (1, str); mHandler.sendMessage (msg); }} public class ThreadB extends Thread {.... Public void run () {... String str = "Test String"; Message msg = mHandler.obtainMessage (1, str); mHandler.sendMessage (msg); }} these are all the contents of the article "how to transfer data in Android". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more 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: 274

*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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report