Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...