我有一个在屏幕上放置一个红色矩形的服务,并且有一个看起来像这样的 onDestroy()
@Override
public void onDestroy() {
Toast.makeText(this, "service done", Toast.LENGTH_SHORT).show();
}
从我的一项活动中,我呼吁像这样终止这项服务:
stopService(new Intent(this, assNavOverrideService.class));
我看到吐司说 onDestroy() 已被调用,但我仍然看到红色矩形并且它仍在运行..
我的清单正在使用:
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" >
我的服务
public class assNavOverrideService extends Service {
Timer timer;
WindowManager.LayoutParams handleParams;
View screenBlock;
View disableStatusBar;
WindowManager winMgr;
@Override
public void onCreate() {
winMgr = (WindowManager)getSystemService(WINDOW_SERVICE);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
disableStatusBar = new TableLayout(getApplicationContext());
handleParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FILL_PARENT,
50,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
// this is to keep button presses going to the background window
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
PixelFormat.TRANSPARENT);
handleParams.gravity = Gravity.TOP;
handleParams.y = 750;
disableStatusBar.setBackgroundResource(R.drawable.fake_nav);
winMgr.addView(disableStatusBar, handleParams);
timer = new Timer();
uiCheckTask tTask = new uiCheckTask();
tTask.setService(this);
timer.schedule(tTask, 50, 10);
// If we get killed, after returning from here, restart
return START_REDELIVER_INTENT;
}
@Override
public IBinder onBind(Intent intent) {
// We don't provide binding, so return null
return null;
}
@Override
public void onDestroy() {
Toast.makeText(this, "service done", Toast.LENGTH_SHORT).show();
}
class uiCheckTask extends TimerTask {
Boolean secDialog = false;
assNavOverrideService myService;
public void setService(assNavOverrideService mS){
myService = mS;
}
public void run() {
Log.v("TICK","TOCKKKKKKKKKKK");
}
}
}