Android app multi-threaded guardian makes it hard to kill it

Source: Internet
Author: User

1. Start a service after Android app is opened

public class Testserviceactivity extends Activity {

/** called when the activity is first created. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);

System.out.println ("Activity Run Thread ID:" + thread.currentthread (). GetName () + "--" +
Thread.CurrentThread (). GetId ());
System.out.println ("Activity's Process ID:" +android.os.process.mypid ());

Intent Intent = new Intent (this,service1.class);
StartService (Intent);
}

}

2. First service

public class Service1 extends Service {


@Override
Public IBinder Onbind (Intent Intent) {
TODO auto-generated Method Stub
return null;
}

@Override
public void OnCreate () {
TODO auto-generated Method Stub
SYSTEM.OUT.PRINTLN ("Service 1 is turned on");
SYSTEM.OUT.PRINTLN ("Service Run thread ID:" + thread.currentthread (). GetName () + "--" +
Thread.CurrentThread (). GetId ());
SYSTEM.OUT.PRINTLN ("Process ID of the service:" +android.os.process.mypid ());
Super.oncreate ();
}

@Override
public void OnDestroy () {
Intent Intent = new Intent (this,service2.class);
StartService (Intent);
Super.ondestroy ();
}


}

3.2nd Service

public class Service2 extends Service {


@Override
Public IBinder Onbind (Intent Intent) {
TODO auto-generated Method Stub
return null;
}
@Override
public void OnCreate () {
SYSTEM.OUT.PRINTLN ("Service 2 is turned on");
Super.oncreate ();
}

@Override
public void OnDestroy () {
Intent Intent = new Intent (this,service1.class);
StartService (Intent);
Super.ondestroy ();
}
}

4. In the manifest file

<service android:name= ". Service1 "
Android:process= "CN.IT.YQQ"
></service>
<service android:name= ". Service2 "></service>

Android app multi-threaded guardian makes it hard to kill it

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.