他们同时启动两个连续服务是否有任何负面影响?如果是这样,有哪些替代方案?
Are their any negatives impacts of launching two continues services at the same time? What are some alternatives if so?
我打算 activity 有两个复选框。我想在屏幕关闭时根据用户选中的标记在后台连续执行一些任务。
final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id);
if ( checkBox1.isChecked() && myServiceIsntRunning() ) {
startService(myService1.class)
if ( checkBox2.isChecked() && myService2IsntRunning() ) {
startService(myService2.class)
}
如果两个复选标记都被选中,我不希望两个任务都使用此方法永远在后台 运行。同时启动这两项服务有什么坏处吗?优化提示文档中似乎没有关于它的任何文档,我看到了这个页面:Can start 2 services from the same activity and can run that activity and two services parrallely in android?。那么,永远并行启动两项服务是个好主意吗?
只要不冲突,多一个服务是可以的运行。一些电池寿命和内存可能会受到影响,具体取决于您的代码。如果可能,可以考虑将它们合并为一个服务来处理2个任务。
我打算 activity 有两个复选框。我想在屏幕关闭时根据用户选中的标记在后台连续执行一些任务。
final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id);
if ( checkBox1.isChecked() && myServiceIsntRunning() ) {
startService(myService1.class)
if ( checkBox2.isChecked() && myService2IsntRunning() ) {
startService(myService2.class)
}
如果两个复选标记都被选中,我不希望两个任务都使用此方法永远在后台 运行。同时启动这两项服务有什么坏处吗?优化提示文档中似乎没有关于它的任何文档,我看到了这个页面:Can start 2 services from the same activity and can run that activity and two services parrallely in android?。那么,永远并行启动两项服务是个好主意吗?
只要不冲突,多一个服务是可以的运行。一些电池寿命和内存可能会受到影响,具体取决于您的代码。如果可能,可以考虑将它们合并为一个服务来处理2个任务。