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)
{
Context context = getApplicationContext();
Intent intent = new Intent(context, StatusBarMain.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.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();
}
}
위에 코드중에
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
Context context = getApplicationContext();
Intent intent = new Intent(context, StatusBarMain.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
다음과 같이 터치다운 이벤트를 받게 되면 액티비티를 시작하는 Service를 만들고 있는데 계속 오류가 되네요 ㅠㅠ
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);를 추가했는데도 오류가 났는데 뭐가 문제일까요?