gpt4 book ai didi

java - 是否从 MainActivity 和 fragment 复制线程启动服务?

转载 作者:行者123 更新时间:2023-12-01 16:47:21 25 4
gpt4 key购买 nike

我从 MainActivityFragment 启动后台服务。

它会创建重复的线程吗?那么这将是 2 个服务在运行?

主要 Activity

protected void onCreate(Bundle savedInstanceState) {
//...
context.startService(new Intent(context,gps_service.class));
//...

fragment

public class FragmentThree extends Fragment {

//... Click method of the button calls
getActivity().startService(new Intent(getActivity(),gps_service.class));

最佳答案

Will it create duplicate threads? So It will be 2 services running?

只会启动一项服务并且只会运行一项服务

关于java - 是否从 MainActivity 和 fragment 复制线程启动服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47864492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com