Android: Check if service is running via. bindService

前端 未结 7 1438
心在旅途
心在旅途 2021-02-18 15:28

What would be the best way to check if an Android Service is running? I am aware of the ActivityManager API, but it seems like the use of the API is not advised for

7条回答
  •  终归单人心
    2021-02-18 16:14

    I had the same need and found that running .bindService with something else already bound, that it would cause errors. I did this right before running .bindService

    try{
        context.unbindService(fetch_connection);
    } catch (IllegalArgumentException e){
        System.out.println("Unbinding didn't work. little surprise");
    }
    

提交回复
热议问题