我正在尝试从服务中显示一个窗口,但不知道如何执行此操作
这是我的代码-
服务onStart
方式
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.main1, null);
WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.type = 2002;
params.format = 1;
params.flags = 40;
params.height = WindowManager.LayoutParams.FILL_PARENT;
params.width = WindowManager.LayoutParams.FILL_PARENT;
manager.addView(view, params);
/** just a timer *****/
textView = (TextView) view.findViewById(R.id.textView1);
final Timer t = new Timer("hello", true);
t.schedule(new TimerTask() {
@Override
public void run() {
textView.post(new Runnable() {
public void run() {
seconds++;
if (seconds == 60) {
seconds = 0;
minute++;
}
if (minute == 60) {
minute = 0;
hour++;
}
textView.setText(""
+ (hour > 9 ? hour : ("0" + hour)) + " : "
+ (minute > 9 ? minute : ("0" + minute))
+ " : "
+ (seconds > 9 ? seconds : "0" + seconds));
}
});
}
}, 1000, 1000);
view.findViewById(R.id.stop).setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
t.cancel();
}
});
但什么都没有出现。如何在服务窗口中显示我的视图?