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

与世无争的帅哥 提交于 2019-12-18 07:08:29

问题


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:


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.



来源:https://stackoverflow.com/questions/35168209/are-their-any-negatives-impacts-of-launching-two-continues-services-at-the-same

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!