Are their any negatives impacts of launching two continues services at the same time? What are some alternatives if so?

时间:2016-02-03 03:54:20

标签: android performance android-service

I am planning on having an activity with two check boxes. I want to do some tasks when the screen is off in the background continuously based on what the user check marks.

     final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id);
         if ( checkBox1.isChecked() && myServiceIsntRunning() ) {
         startService(myService1.class)

  if ( checkBox2.isChecked() && myService2IsntRunning() ) {
         startService(myService2.class)
         }

If both the checkmarks are checked, I wan't both tasks to constantly run in the background forever using this method. Is there any harm in launching both services at once? There doesn't appear to be any documentation about it in the Optimization tips documentation, and I saw this page about it: Can start 2 services from the same activity and can run that activity and two services parrallely in android?. So, would starting two services parallely forever be a good idea?

1 个答案:

答案 0 :(得分:1)

As long as they do not conflict, it is OK to have more than one service running. Some battery life and memory may be affected, depending on your code. If possible, you can consider merging them to one service to handle 2 tasks.