참고 : http://ccdev.tistory.com/14
public class ConfigActivity extends Activity {
private Button onBtn, offBtn;
@Override
protected void onCreate(Bundle savedInstanceSate){
super.onCreate(savedInstanceSate);
setContentView(R.layout.activity_main);
onBtn = (Button)findViewById(R.id.btn1);
offBtn = (Button)findViewById(R.id.btn2);
onBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(this, ScreenService.class);
startService(intent);
}
});
offBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(this, ScreenService.class);
stopService(intent);
}
});
}
}
오류
Error:(27, 33) error: no suitable constructor found for Intent(<anonymous OnClickListener>,Class<ScreenService>)
constructor Intent.Intent(String,Uri) is not applicable
(argument mismatch; <anonymous OnClickListener> cannot be converted to String)
constructor Intent.Intent(Context,Class<?>) is not applicable
(argument mismatch; <anonymous OnClickListener> cannot be converted to Context)
Error:(34, 33) error: no suitable constructor found for Intent(<anonymous OnClickListener>,Class<ScreenService>)
constructor Intent.Intent(String,Uri) is not applicable
(argument mismatch; <anonymous OnClickListener> cannot be converted to String)
constructor Intent.Intent(Context,Class<?>) is not applicable
(argument mismatch; <anonymous OnClickListener> cannot be converted to Context)