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)06/03 Report--
This article mainly introduces how to use componentname, the introduction in the article is very detailed, has a certain reference value, interested friends must read!
ComponentName, as its name implies, is the name of the component. By calling the setComponent method in Intent, we can open an Activity or service in another application.
How to instantiate a ComponentName
Instantiating a ComponentName requires two parameters. The first parameter is the name of the package to start the application, which refers to the package name of the application listed in the manifest file:
The second parameter is the full name of the Activity or Service you want to launch (package name + class name). The code is as follows:
Start an Activity:
Intentintent=newIntent ()
Intent.setComponent (newComponentName ("com.example.otherapp")
"com.example.otherapp.MainActivity2"))
StartActivity (intent)
ComponentName usage
ComponentName: Activity, Service.
ComponentNamechatActivity=newComponentName (param1,param2)
Package name of the application where param1:Activity and Service are located
Package name + class name of param2:Activity and Service
Activity:
ComponentNamechatActivity=newComponentName ("com.npf.chat", "com.npf.chat.ui.ChatActivity")
Intentintent=newIntent ()
Intent.setComponent (chatActivity)
StartActivity (intent)
Service:
ComponentNamechatService=newComponentName ("com.npf.chat", "com.npf.chat.ui.ChatService")
Intentintent=newIntent ()
Intent.setComponent (chatService)
StartService (intent)
Note:
If the Activity is not an application portal (the entry Activity defaults to android:exported= "true"), you need to add android:exported= "true" to the manifest file. Service also needs to add android:exported= "true". Allow external application calls.
The above is all the contents of this article "how to use componentname". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow 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.