public class AlwaysOnTopService extends Service {
private Button mPopupView;
private WindowManager.LayoutParams mParams;
private WindowManager mWindowManager;
private OnTouchListener mViewTouchListener = new OnTouchListener() {
@Override public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
Intent intent = new Intent(AlwaysOnTopService.this,Main.class);
startActivity(intent);
}
return true;
}
};
@Override
public IBinder onBind(Intent arg0) { return null; }
@Override
public void onCreate() {
super.onCreate();
mPopupView = new Button(this);
mPopupView.setBackgroundColor(Color.argb(255, 255 , 255, 255));
mPopupView.setOnTouchListener(mViewTouchListener);
mParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
mParams.gravity = Gravity.TOP;
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mPopupView, mParams);
}
@Override
public void onDestroy() {
if(mWindowManager != null) {
if(mPopupView != null) mWindowManager.removeView(mPopupView);
}
super.onDestroy();
}
}
다음과 같이 코드를 짰는데 버튼에 대한 터치이벤트를 가하면 에러가 자꾸나네요 ㅠㅠ 뭐가 문제일까요 ㅠㅠ