我從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。 –