About the Android app KeepAlive

Source: Internet
Author: User

Typically, companies need to keep their products alive for as long as possible in the user's phone, including not being affected by large numbers, manually clearing the background, and so on. Here one way is to double process guard;

Model:

    

Two service establishes an IPC communication by Aidl, that is to bind each other in the Onstartcommand method of the two service by Aidl Way;

For example, in S1:

    

    @Override    publicint int int startid) {        this . Bindservice (new Intent ( This, LocalService2.  Class), Conn, context.bind_important);         return start_sticky;    }

In the Onbind:

   @Override    public  ibinder onbind (Intent Intent) {        //  TODO: Return the communication channel to the service.        return mybinder;    }

And Mybinder is the concrete realization of aidl:

    Private classMybinderextendsiprocessconnection.stub {@Override Public voidBasictypes (intAnint,LongAlong,BooleanAboolean,floatAfloat,DoubleAdouble, String astring)throwsremoteexception {} @Override Public voidGetprocessname ()throwsremoteexception {log.i ("Process", "LocalService1"); }    }

This establishes the connection in two serivce, and through the Conn this serviceconnection to listen to the connection situation, whether the disconnection, the disconnection means that one side is killed

    Private class extends serviceconnection {        @Override        publicvoid  onserviceconnected (componentname Name, IBinder service) {        }        @Override        publicvoid  onservicedisconnected (componentname name) {        }    }

When disconnected, it will callback onservicedisconnected this method, the inside restart another serivce and bind he can guarantee two service to listen to each other, guard each other.

About the Android app KeepAlive

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.