One application in Android launches another application and passes the data.

Source: Internet
Author: User

One, Android One application launched another application when there are 2 methods.

The first is to know the specific action,category of the app being invoked (typically the first two values are the default, that is, the following method), the package name and the class name

public void Start (View v)    {    Intent intent2 = new Intent ("Android.intent.action.MAIN");  Intent2.addcategory ("Android.intent.category.LAUNCHER");              ComponentName cn = New ComponentName ("Com.example.secondapp", "com.example.secondapp.MainActivity");              Intent2.setcomponent (CN);  
Intent2.putextra ("name", "ZP"); This.startactivity (Intent2); }

The second way is to only know the application's package name, this way with more

public void Start2 (View v)    {    Packagemanager p=this.getpackagemanager (); Intent in= P.getlaunchintentforpackage ("Com.example.secondapp"), if (in!=null) {In.putextra ("name", "ZP"); This.startactivity ( in);} Else{toast.maketext (This, "Yo, hurry to download and install this app", Toast.length_long). Show ();}    }

Second, in the start of the secondary program, you can pass the parameters, that is, using intent Putextra () value, or bulk with bundles, such as the transfer of "a startup application" see http://www.2cto.com/kf/201409/332952.html

Can be Intent.putextra first ("name", "ZP");Again startactivity (Intent) uses the following code in the launched application: You can get the data.
public class Mainactivity extends actionbaractivity {private TextView ed;    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_main);        Ed= (TextView) Findviewbyid (R.ID.TX);        Intent Intent =getintent ();        Bundle bundle = Intent.getextras ();        if (bundle! = null) {        string name= (String) bundle.get ("name");        Ed.settext (name);        }            }

  

  

One application in Android launches another application and passes the data.

Related Article

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.