package com.example.app1;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
public class menu extends Activity {
Intent intent;
private Switch swc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
intent = new Intent(this, action.class);
swc = (Switch)findViewById(R.id.switch1);
swc.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecking) {
String str = String.valueOf(isChecking);
if(isChecking){
intent = new Intent (menu.this, action.class );
startService(intent);
moveTaskToBack(true);
}
else{
intent = new Intent (menu.this, action.class );
stopService(intent);
}
}
});
}
public void go_info (View v) {
Intent myintent = new Intent(this, option.class);
startActivity(myintent);
}
}
코드는 이런 형식인데 버튼으로 구현할 때는 서비스가 실행이 잘 되었는데 스위치는 on해도 어플이 꺼지기만 해도 서비스 실행이 안되네요... 방법있나요 ㅜ