Special applications in Android with system special functions to assist with communication problems

Source: Internet
Author: User

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.

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.