【发布时间】:2020-02-09 23:21:49
【问题描述】:
我只想在我的服务完全停止时才做一些事情。
所以我将一个公共静态变量初始化为 false,在 onCreate() 中初始化为 true,在 onDestroy() 中初始化为 false。
在我的活动中:
if(TripService.trip_service_state)
{
stopService(newIntent(ProfileActivity.this,TripService.class));
while (TripService.trip_service_state);
do_stuff();
}
为我服务:
public static boolean trip_service_state=false;
onCreate()
{
super.onCreate();
trip_service_state=true;
}
onDestroy()
{
trip_service_state=false;
super.onDestroy();
}
现在,当我的服务运行时,应用收到 NOT RESPONDING 消息。
【问题讨论】:
-
你想让
do_stuff();函数在while循环之后还是里面执行? -
while 循环之后。
标签: java android binary-semaphore