In the actual project application, one of the recent requirements is to enter a special application, a function of the system does not work. Of course, there are many ways this communication can be done. I can think of at least a few of the following
1, the use of property familiar to achieve, such words need to add a special attribute;
2, the use of the database, add a record in the database, enter the application of the time set, in the system can be used in the content observer or in the special event when the first judge read this value can also;
3, the use of intent, send a special intent out, in the system to install a filter;
4, using Getrunningtasks, that is, the operation of activities service information to judge;
The author compares above these four kinds, the realization all can realize, but uses the existing system some information to solve this question is not better! So the author chooses scenario 4. That is to do an interface, in this interface to determine whether this particular application is in the most foreground. This is still very useful and the simple code is as follows:
public boolean judgetopactivityisreversevideo (int status) {String topactivityclassname=null; if (AM = = null) am = (Activitymanager) (Mcontext.getsystemservice (Mcontext.activity_service)); list<runningtaskinfo> Runningtaskinfos = am.getrunningtasks (1); if (Runningtaskinfos! = null) {ComponentName f= Runningtaskinfos.get (0). Topactivity;topactivityclassname=f.getclassname ();} SLOG.D (TAG, "# # #topActivityClassName:" +topactivityclassname); if (topactivityclassname!=null&& Topactivityclassname.startswith ("Com.softwinner.reversevideo.ReverseVideo")) {if (1 = = status) mreversevideoappen ter = true;/*in apk, reverse video comming*/else mreversevideoappenter = false;/*in apk, reverse video Outgoing*/re Turn true;} else if (true = = Mreversevideoappenter) {/*enter reversevideo apk, reverse video signal Comming,then Press BA Ck/home key, APK exit, but reverse video signal don't exit, so we need a flag note this special status*/Mreversevid Eoappenter =False return true;} return false; }
Through the author's test practice, this method is completely feasible.