One application starts the Activity of another application

Source: Internet
Author: User

First (I wrote it myself): In my opinion, there are some main activities on the Internet that I don't want to start another application.

// These Codes start the main Activity of another application. Of course, you can also start any Activity.
ComponentName componetName = new ComponentName (
// This is the package name of another application
"Com. poynt. weibo ",
// This parameter is the Activity to be started
"Com. poynt. weibo. ui. IndexActivity ");

Try {
Intent intent = new Intent ();
Intent. setComponent (componetName );
StartActivity (intent );
} Catch (Exception e ){
// Toast. makeText (getApplicationContext (), "You can prompt the user that the application is not found, or do other operations here! ", 0). show ();

}
Copy code


Second

: After the Activity of another program is started, the parameters are passed!
Call another Android program B in app a and transmit data to app B at the same time.

ComponentName componentName = new ComponentName (
"Com. xiaohua. player. activity ",
"Com. xiaohua. player. activity. PlayerActivity ");
Intent intent = new Intent ();
Bundle bundle = new Bundle ();
Bundle. putString ("resUrl", resurl );
Bundle. putSerializable ("picUrlList", picurllist );
Intent. putExtras (bundle );
Intent. setComponent (componentName );
StartActivity (intent );
Note:
Com. xiaohua. player. activity: Package path
PlayerActivity: Activity Class
ResUrl: String type
PicUrlList: array or object
After the application is installed, it can be called as described above.


Accept activity:
Public void getParameterByIntent (){
Intent mIntent = this. getIntent ();
String resUrl = mIntent. getStringExtra ("resUrl ");
String [] picUrlList = (String []) mIntent. getSerializableExtra ("picUrlList ");
If (null! = PicUrlList ){
Int count = picUrlList. length;
For (int I = 0; I <count; I ++ ){
Log. e ("tag", "picUrlList [" + I + "]" + picUrlList );
}
}
}

From: http://hi.baidu.com/huaxinchang/blog/item/5fa81903474097f409fa9305.html
Copy code

 

Third: Call the activity in another apk in one apk.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.