In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to understand the communication between two running Activity in Android application development? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
In Android application development, it's easy to launch an Activity from one Activity and pass some data to the new Activity, but there may be a slight problem when you need to get the Activity running in the background back to the foreground and pass some data.
First, by default, when you boot to an Activity through Intent, even if there is already the same running Activity, a new Activity instance is created and displayed. In order not to instantiate Activity multiple times, we need to implement single-task mode by configuring the load mode (launchMode) of activity in AndroidManifest.xml, as shown below:
twelve
When launchMode is singleTask, launch an Activity through Intent. If an instance already exists in the system, the system will send the request to this instance. However, instead of calling the onCreate method that normally processes the request data, the system will call the onNewIntent method, as shown below:
1protected void onNewIntent (Intent intent) {2super.onNewIntent (intent); 3setIntent (intent); / / must store the new intent unless getIntent () will return the old one4processExtraData (); 5}
Don't forget that the system may kill the Activity running in the background at any time. If this happens, the system will call the onCreate method instead of the onNewIntent method. A good solution is to call the same method for processing data in the onCreate and onNewIntent methods, as shown below:
01public void onCreate (Bundle savedInstanceState) {02super.onCreate (savedInstanceState); 03setContentView (R.layout.main); 04processExtraData (); 05} 0607protected void onNewIntent (Intent intent) {08super.onNewIntent (intent); 09setIntent (intent); / / must store the new intent unless getIntent () will return the old one10processExtraData () 11} 1213private void processExtraData () {14Intent intent = getIntent () 15//use the data received here16} this is the answer to the question about how to understand the communication between two running Activity in Android application development. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.