A few days ago, the technical director of the egg pain to achieve similar to install a QQ mailbox, and then can use QQ mailbox Calendar of a thing, equivalent to an app generated two icons, but the difference is to click on different icons can enter different applications, such as the effect.
The effect of Baidu a day do not know how to start, can only do their own, to share their own solution to the problem of the process, presumably this
1. First analysis of the entire desktop luncher is an activity, all the icons are a button, click on the icon is to click a button and then go to perform activity
2. View the source code for the Launcher framework layer, https://android.googlesource.com/platform/packages/apps/Launcher/+/master/src/com/ The Android/launcher/launcher.java path is this, which can be viewed by flipping the wall. This kind of actually and I write the class also no difference. Because launcher is a successor to the activity.
Public final class Launcher extends Activity implements View.onclicklistener, Onlongclicklistener
Next we just need to find the Click event on the line, where he will judge whether the click View is a folder or an application,
public void OnClick (View v) { Object tag = V.gettag (); if (tag instanceof applicationinfo) { //Open shortcut final Intent Intent = ((applicationinfo) tag). Intent; Startactivitysafely (intent); } else if (tag instanceof folderinfo) { Handlefolderclick ((folderinfo) tag); } }
Next look at startactivitysafely, which is actually handling the next exception and adding some flags, but flag is the point. Parsing will continue to say flag
void startactivitysafely (Intent Intent) { intent.addflags (intent.flag_activity_new_task); try { startactivity (intent); } catch (Activitynotfoundexception e) { Toast.maketext (this, R.string.activity_not_found, Toast.length_short). Show (); } catch (SecurityException e) { Toast.maketext (this, R.string.activity_not_found, Toast.length_short). Show (); E (Log_tag, "Launcher does not" has the permission to launch "+ Intent + ". Make sure to create a MAIN intent-filter for the corresponding activity "+ " or with the exported attribute for this a Ctivity. ", E); } }
Here is actually very simple, is to add a flag, this flag role is very big, carefully talk about
FLA G_activity_new_task Is there a and the activated activity have the same affinity for the task stack (i.e. taskaffinity) If there is a direct to this
Stack moves to the foreground, keeping the state of the stack intact, i.e. the activity order in the stack does not change, and if not, create a new stack to hold the activated activity. That's why we click on the Home button and then click on the icon to revert to the original state instead of recreating an activity.
Through the above analysis will probably be able to achieve such things, and now I just need to let them run in a different task stack, can not affect each other. The following is the approximate implementation of the process, for reference only, because this is only a basic model. We actually put a lot of business into it.
The approximate idea is that this is the implementation of the Code. The main point is to put a field called Class and then click on the icon to get this field, open the corresponding activity can
public class Bootupactivity extends Activity {private Handler Handler = new Handler () {@Override public void Handlemessage (Message msg) {super.handlemessage (msg); Switch (msg.what) {case 1:break; } } }; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); LOG.I ("Bootupactivity", "OnCreate"); String className = Getintent (). Getstringextra ("Class"); if (classname==null) {addshortcuttodesktop (BootupActivity.this.getString (r.string.shopping_app_name), r.drawab Le.shopping_ic_launcher, Activity1.class.getName (), activity1.class); Addshortcuttodesktop (BootupActivity.this.getString (r.string.xiaohua_app_name), R.drawable.xiaohua_ic_launcher, Activity2.class.getName (), activity2.class); Startappprocess (Activity1.class.getName ()); }else {startappprocess (className); }} private void Addshortcuttodesktop (string lable, int iconres, string destclassname, class<?> bootupclass) { Intent shortcut = new Intent ("Com.android.launcher.action.INSTALL_SHORTCUT"); No rebuilding Shortcut.putextra ("duplicate", false); Shortcut.addflags (Intent.flag_activity_multiple_task); Setting name Shortcut.putextra (Intent.extra_shortcut_name, lable); Setting icon if (iconres!=0) {Shortcut.putextra (Intent.extra_shortcut_icon_resource, Intent.ShortcutIconResource.fromContext (this, iconres)); }//Create a broadcast intent intent intent = new Intent (this, bootupclass); Intent.putextra ("Class", destclassname); Intent.setaction (Intent.action_main); Setting Intent Shortcut.putextra (intent.extra_shortcut_intent, intent); Send broadcast SEndbroadcast (shortcut); } private void Startappprocess (String bootupclass) {Activitymanager am = (activitymanager) getsystemservice (ACT Ivity_service); Intent i = new Intent (); I.setcomponent (New ComponentName (This.getpackagename (), bootupclass)); I.putextra ("Class", Bootupclass); This.startactivity (i); }}
The following is required to be configured in the configuration file, you need to note that the android:taskaffinity this property, different activity needs to be configured differently. Configure the affinity of the main activity and the default open activity to be the same. Ensure that you can open the same task stack by clicking on the desktop icon and app icon. Then pay attention to putting the main bootupactivity in the first place. Everything else needs to be added with an action and is the same as the main one.
<application android:icon= "@drawable/ic_launcher" Android:name= "Com.zlh.combined.MainApp" Android oid:taskaffinity= "COM.P" > <activity android:name= ". Bootupactivity "android:logo=" @drawable/ic_action_search "> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "android.in Tent.category.LAUNCHER "/> </intent-filter> </activity> <activity an Droid:name= ". Activity1 "android:taskaffinity=" COM.P "android:process=":p roxy2 "> <in tent-filter> <action android:name= "Android.intent.action.MAIN"/> </intent-filter> ; </activity> <activity android:name= ". Activity2 "android:taskaffinity=" com.c "android:process=":p roxy3 "> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> </in Tent-filter> </activity> </application> <!--Create a desktop shortcut--<uses-permiss Ion Android:name= "Com.android.launcher.permission.INSTALL_SHORTCUT"/>
Android implementation QQ mailbox multiple icon effect