我从MainActivity
以及Fragment
开始后台服务。是否从MainActivity和碎片复制线程开始服务?
它会创建重复线程吗?所以这将是2服务运行?
MainActivity
protected void onCreate(Bundle savedInstanceState) {
//...
context.startService(new Intent(context,gps_service.class));
//...
片段
public class FragmentThree extends Fragment {
//... Click method of the button calls
getActivity().startService(new Intent(getActivity(),gps_service.class));
可能重复的:https://stackoverflow.com/a/8019919/5154891。 –