Android launches another main screen hide icon app from one app

Source: Internet
Author: User

Start b.apk with a.apk, and B's icon is not visible on the phone's main screen.

First, a new A, B two Android project (new HelloWorld project similar), in a project to increase the Click event (Launch button to launch the B app).

Second, in the B application To modify the B manifest. xml <intent-filter>...</intent-filter> content can hide the B app icon.

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.rainwii.message"Android:versioncode= "1"Android:versionname= "1.0" >    <USES-SDKandroid:minsdkversion= "8"android:targetsdkversion= "+" />    <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >        <ActivityAndroid:name= "Com.rainwii.message.MainActivity"Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <!--This sentence can be commented out, can also be kept -               <!--<category android:name= "Android.intent.category.LAUNCHER"/> -               <!--data is critical; The Android:scheme code can be commented. If you want to write the content to write casually, but and want to and a application in the jump information consistent -                <DataAndroid:host= "Mainactivity"Android:scheme= "ABC"                       />            </Intent-filter>        </Activity>          </Application></Manifest>

The icon to install the B app is now invisible on the phone.

Third,a button in the application to add code to start the B application.

 PackageCom.rainwii.main;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.content.ComponentName;Importandroid.content.Intent;ImportAndroid.content.pm.PackageManager;ImportAndroid.view.Menu;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.Toast; Public classMainactivityextendsActivity {Button Startappbutton; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Startappbutton=(Button) Findviewbyid (R.id.button1); Startappbutton.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {//TODO auto-generated Method Stub               Intent Intent = new Intent ();                ComponentName cn = New ComponentName ("Com.rainwii.message", "com.rainwii.message.MainActivity");                Intent.setcomponent (CN); Uri uri = uri.parse ("abc");//This should be consistent with the label in data in the B program Intent.setdata (URI);            StartActivity (intent);                        }        }); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; }    }

Note: componentname (component name) is used to open activity or services in other applications.

Usage:

Intent it=New  Intent (); It.setcomponent (new  componentname (String packagename,string Activityname)); StartActivity (it) ;

Well, you've implemented an app that launches another main screen hide icon from one app.

Android launches another main screen hide icon app from one app

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.